Function pointers in SDCC

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Function pointers in SDCC

Post by jorgegv »

Hi,

can anyone give some advice about why this code fails to compile with SDCC? (with sccz80, it does not even parse correctly...)

Code: Select all

// zcc +zx -compiler=sdcc -c pepe.c
// This generates an error!
typedef void (codeset_function_t)( void );

extern codeset_function_t my_user_init;
extern codeset_function_t my_user_game_init;
extern codeset_function_t my_user_game_loop;
codeset_function_t *codeset_functions[ 3 ] = {
        &my_user_init,
        &my_user_game_init,
        &my_user_game_loop,
};
I have seen this issue which seems related, but it's been open for 5 years:

https://sourceforge.net/p/sdcc/bugs/2497/

Any advice? My current B-plan is to replace the function pointers with void* pointers, but I'd loose type checking and all...

TIA
J.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: Function pointers in SDCC

Post by dom »

If you write this:

Code: Select all

typedef void (*codeset_function_t)( void );
it will parse/compile correctly in both compilers.
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Function pointers in SDCC

Post by jorgegv »

Thanks, this works indeed. I was doing it this way at the beginning (it's the standard way, after all), but while I was with it, I was bitten by the "00_main.c" bug mentioned in other topic, so this went under the radar.

Thanks
J.
Post Reply