I'd appreciate a kick in the right direction because I can't get function pointers to work:
I want to store pointers to functions (tasks) in an array and be able to call the functions by indexing the array. Here is main.c and my Makefile comments on anything you spot gratefully received. Jonathan ---------------MAIN.C------------------ #include "pic18fregs.h" #include "main.h" #pragma stack 0x60 <---------------not sure if this is right for the pic18f248 typedef struct t_tasks { void (*fp)(void); } tasks; void main(void) { struct t_tasks mytasks[10]; mytasks[0].fp = ledoff; mytasks[1].fp = ledon; mytasks[2].fp = pause; init(); while(1) { ledon(); pause(); ledoff(); pause(); // mytasks[0].fp(); <--------- With this line commented led flashes nicely When uncommented gpsim complains at movff r0x02, PCLATU And the led does not even flash one time Error is: "attempt read from invalid file register" } } void ledon(void) { LED_STATUS = 0; } void ledoff(void) { LED_STATUS = 1; } void pause(void) { int i, j; for (j = 0; j < 10; j++) { for (i = 0; i < 10000; i++) { } } } ----------MAKEFILE-------------- main.hex: main.o gplink -w -r -o main.hex -m main.o -I /usr/share/sdcc/lib/pic16 pic18f248.lib libsdcc.lib crt0i.o main.o: main.asm gpasm -c -a inhx32 main.asm main.asm: main.c main.h Makefile sdcc -S main.c -mpic16 -p18f248 clean: $(RM) *.asm *.cod *.lst *.hex *.p *.d *.lnk *~ *.o *.cof *.map prog: picp /dev/ttyS0 18f248 -ef -wp main.hex sim: gpsim -p18f248 main.cod ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user