CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Complex code made up with struct not working?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Complex code made up with struct not working?
PostPosted: Tue Feb 03, 2009 1:48 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 03, 2009 2:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 03, 2009 5:02 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group