Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#209 function pointers with >2 params

open
nobody
None
5
2007-05-29
2007-05-27
No

SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.7.0 #4814 (May 25 2007) (MINGW32)

compiled with just `sdcc file.c`:

----->8-----
typedef char (*cb_t)(char a, char b);
cb_t cb;

char cb_sample(char char a, char b) {
return a+b;
}

void main(void) {
cb = cb_sample;
cb(1, 2);
}
----->8-----

Produces:
?ASlink-Warning-Undefined Global '_cb_PARM_2' referenced by module 'minimal'

Compiler doesn't generate _cb_PARM_2, which is used in the function:
`mov a,_cb_sample_PARM_2`
but tries to write second param to _cb_PARM_2 when calling that pointer.

One param is ok, as it goes through the DPL. Second one won't work.

When function's not reentrant, this is probably not really fixable - if second param uses global variable, it should be caught with an *error* and proper message suggesting reentrant function.

Marking function / pointer as reentrant fixes it of course.

Discussion

  • Maarten Brock
    Maarten Brock
    2007-05-28

    Logged In: YES
    user_id=888171
    Originator: NO

    This is known behaviour and I thought it was in the manual too. But I just looked and could not find it.
    Maybe a better error check can be created too.

     
  • Maarten Brock
    Maarten Brock
    2007-05-29

    • labels: 101550 -->
     
  • Maarten Brock
    Maarten Brock
    2007-05-29

    Logged In: YES
    user_id=888171
    Originator: NO

    I've updated the manual stating that indirectly called functions need to be reentrant.

    The request for a better error message I leave open, but move it to feature requests.