On Thursday 17 April 2008 00:17, Andy wrote: > Indirect calls - ie simple function pointers are safe! > > It is only when you try and do some arithmetic with them that there is > potential problem. The only reason to use arithmetic is for ASM related > manipulations. (but very useful!) > > For example , (excuse syntax mistakes) > > void foo(void) {} > > (void * p1) (void); > > p1 = &foo; //NO PROBLEM [...]
Doubtful is avr6 case with binutils. Look, please, the program below. It uses only simple function pointers, no arithmetic. Thanks, Dmitry. /* avr-gcc 4.4-20080404 + binutils 2.18 produce incorrect code: the foo4() function stores 0 value to 'vp' variable. Options: -W -Wall -Os -mmcu=atmega2560 */ #define BIGCODE() asm volatile (".rept 30000\n\tnop\n\t.endr") void (* volatile vp) (void); __attribute__((noinline)) void foo1 (void) { BIGCODE(); vp = foo1; } __attribute__((noinline)) void foo2 (void) { BIGCODE(); vp = foo2; } __attribute__((noinline)) void foo3 (void) { BIGCODE(); vp = foo3; } __attribute__((noinline)) void foo4 (void) { BIGCODE(); vp = foo4; } int main () { foo1 (); foo2 (); foo3 (); foo4 (); return 0; } _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list