David McNab <[EMAIL PROTECTED]> wrote: > // define a macro to create a 'function pointer table handle' > #define pgm_get_functab(tab) (FuncPtrTable)(&tab[0])
&tab[0] is the same as tab. > I tried the approach of: > fptr = (FuncPtr)pgm_read_word(&funcs_table[0] + i * 2); > but it has a huge footprint of 48 bytes ... Does it? foo.c: #include <avr/pgmspace.h> typedef void (*FuncPtr)(void); void func1(void); void func2(void); void func3(void); FuncPtr funcs_table[] PROGMEM = { func1, func2, func3 }; void dorun(int i) { FuncPtr fptr; fptr = (FuncPtr)pgm_read_word(funcs_table + i); fptr(); } yields: ..global dorun .type dorun, @function dorun: movw r30,r24 lsl r30 rol r31 subi r30,lo8(-(funcs_table)) sbci r31,hi8(-(funcs_table)) lpm r24, Z+ lpm r25, Z movw r30,r24 icall ret Btw., you apparently have problems still understanding how pointers are calculated in C. The complicated "&tab[0]" construct is a slight indication of that, but you've also made the error of trying to manually multiply by 2 in your access macro. I left that off, as it would have given completely wrong code. -- cheers, J"org .-.-. --... ...-- -.. . DL8DTL http://www.sax.de/~joerg/ NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-) _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list