Lv Zheng,
If you think you found a bug please file it in SDCC's bug tracker at
sourceforge. On the mailinglist it is bound to be forgotten.
Greets,
Maarten Brock
> Hi, all
>
> We post this message for someone who might be put in a great
> quandary like us.
>
> Please look at the sample codes:
>
> ============================================================
> #define NR_TEST_FUNCS 2
> typedef code struct test_funcs {
> void (*non)(void);
> } test_funcs_c;
>
> test_funcs_c * data test_funcs[NR_TEST_FUNCS];
> uint8_t nr_test_funcs = 0;
>
> void register_test_func(test_funcs_c *funcs)
> {
> if (nr_test_funcs < NR_TEST_FUNCS-1) {
> test_funcs[nr_test_funcs] = funcs;
> nr_test_funcs++;
> }
> }
>
> void test_non(void)
> {
> dbg_dump(1);
> }
>
> test_funcs_c funcs1 = {
> test_non,
> };
>
> test_funcs_c funcs2 = {
> test_non,
> };
>
> static void test_funcs_ptr(void)
> {
> uint8_t i;
> test_funcs_c *p;
>
> register_test_func(&funcs1);
> register_test_func(&funcs2);
>
> for (i = 0; i < nr_test_funcs; i++) {
> /* the way can work */
> p = test_funcs[i];
> (p->non)();
>
> #if 0
> /* the way cannot work */
> (test_funcs[i]->non)();
> #endif
> }
> }
> ============================================================
>
> It seems a compiler bug, compiler cannot generate correct
> codes for structure member location in the latter one.
> Please look at the generated codes for the differences:
>
> ============================================================
> ; p = test_funcs[i];
> mov a,r2
> add a,r2
> add a,#_test_funcs
> mov r0,a
> mov ar3,@r0
> inc r0
> mov ar4,@r0
> dec r0
> mov dpl,r3
> mov dph,r4
> ; (p->non)();
> clr a
> movc a,@a+dptr
> mov r3,a
> inc dptr
> clr a
> movc a,@a+dptr
> mov r4,a
> push ar2
> push ar3
> push ar4
> mov dpl,r3
> mov dph,r4
> lcall __sdcc_call_dptr
> pop ar4
> pop ar3
> pop ar2
> ============================================================
> ; (test_funcs[i]->non)();
> mov a,r2
> add a,r2
> add a,#_test_funcs
> mov r0,a
> mov ar0,@r0
> mov ar3,@r0
> inc r0
> mov ar4,@r0
> dec r0
> push ar2
> push ar3
> push ar4
> mov dpl,r3
> mov dph,r4
> lcall __sdcc_call_dptr
> pop ar4
> pop ar3
> pop ar2
> ============================================================
>
> Best regards/Lv Zheng
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user