Menu

#3668 [r3ka] Why does this generate a warning?

closed-rejected
None
Rabbit
5
2025-08-09
2023-10-13
D-mo
No

Why does casting void pointer into function pointer below generate a warning?

void main(void)
{
    void *foo = 0;
    ( (void (*)())foo )();
}

Compiled with:

user@linux:~$ sdcc -mr3ka test.c 
test.c:9: warning 244: pointer types incompatible 
from type 'void generic* auto'
  to type 'void function ( void ) code* fixed'

sdcc version:

user@linux:~$ sdcc -v
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/sm83/tlcs90/ez80_z80/z80n/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502 TD- 4.3.0 #14184 (Linux)
published under GNU General Public License (GPL)

Related

Wiki: NGI0-Commons-SDCC

Discussion

  • Philipp Klaus Krause

    The C standard (unlike POSIX) does not require support for casts between pointers to objects and pointers to functions. For r3ka, this should currently work in SDCC, but IMO a warning still makes sense.
    In the future, when we introduce a medium memory model for m3ka (i.e. allowing more than 64K of code by using the XPC segment, for -mr3ka --model-medium, function pointers will be 24 bits, while object pointers will still be 16 bits - we already have -mstm8 --model-large behave that way).

     

    Last edit: Philipp Klaus Krause 2025-08-09
  • Philipp Klaus Krause

    • status: open --> closed-rejected
    • assigned_to: Philipp Klaus Krause
     

Log in to post a comment.

MongoDB Logo MongoDB