View previous topic :: View next topic |
Author |
Message |
Guest
|
Complex code made up with struct not working? |
Posted: Tue Feb 03, 2009 1:48 pm |
|
|
Hi
Small demonstration only, just a rip out of production code!
Both compile without errors.
Why is it needed to split the not working examples out, and use local help variable? I think it's a problem the compiler cant handle complex term?
The ex. is _not_ using any pointer only some "struct".
Code: | struct _fo{
int8 cnt;
int1 bit;
}fo[4];
struct _br{
int16 f1bit,f2bit;
int1 end,rej;
}br[10];
//1) working
void t1(){
int16 tmp,tmpold;
int8 cnt;
tmp=get_timer1();
cnt=fo[2].cnt;
tmpold=br[cnt].f2bit;
if (tmp<tmpold){
br[cnt].f2bit=(0xffff-tmpold)+tmp;
} else {br[cnt].f2bit=tmp-tmpold;}
}
//2) not working
void t2(){
int16 tmp;
tmp=get_timer1();
if (tmp<br[fo[2].cnt].f2bit){
br[fo[2].cnt].f2bit=(0xffff-br[fo[2].cnt].f2bit)+tmp;
} else {br[fo[2].cnt].f2bit=tmp-br[fo[2].cnt].f2bit;}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 03, 2009 2:47 pm |
|
|
Quote: | I think it's a problem the compiler cant handle complex term? |
As a rule, don't "push" this compiler. It's better not to go too complex. |
|
|
mayler
Joined: 13 Nov 2008 Posts: 10
|
|
Posted: Tue Feb 03, 2009 5:02 pm |
|
|
I agree with PCM. This is not gcc/Visual C/Turbo C/ whatever pc compiler C. ThereĀ“s no sense make a programming "made to a computer" for a microcontroller with a limited arch. Altough the syntax is almost the same, the thinking is very different.
The CCS has a lot of obscure bugs with more complex elements, like structs and pointers... Always double check type conversions, pointers and structs. I had serious problems using cast in recent versions. |
|
|
|