[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] gcc builds wrong code?
From: |
Klaus Rudolph |
Subject: |
[avr-gcc-list] gcc builds wrong code? |
Date: |
Sun, 25 Jul 2004 20:20:07 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.6) Gecko/20040114 |
Hi all,
I wrote the following testcode and found that if a table of pointers to
functions
recides in flash "attribute progmem" the code is not correct.
Is the compiler doing the wrong or am I the problem :-)
Compiler Version:
avr-gcc (GCC) 3.4.0
Build my code with:
avr-gcc -O2 -g -mmcu=at90s8515 test.c -c
avr-gcc -O2 -g -mmcu=at90s8515 test.o -o go
The code generation is wrong if version 1 is enabled, with version 2 the
code is
correct.
Thanks
Klaus
///////////////////////////////// test.c /////////////////////////////
#ifdef __AVR__
#include <avr/io.h>
#endif
int f2(int a) {
return a+1;
}
int f3(int a) {
return a*2;
}
int f4(int a) {
return a*2+1;
}
volatile int all=0;
typedef int(*fp_t)(int) ;
// Version 1 fail
const fp_t __attribute__ ((progmem)) fp[]={f2,f3,f4,0} ;
//Version 2 ok
//const fp_t fp[]={f2,f3,f4,0} ;
int main() {
int index=1;
int tmp=1;
while (fp[index]) {
tmp+=(fp[index++])(tmp);
}
all=tmp;
return 0;
}
- [avr-gcc-list] gcc builds wrong code?,
Klaus Rudolph <=