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

Conditional Expression Operator ?: error

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



Joined: 05 Sep 2007
Posts: 46
Location: Londrina - Brazil

View user's profile Send private message

Conditional Expression Operator ?: error
PostPosted: Fri Jul 25, 2008 8:50 am     Reply with quote

I can't understand why this code generates an error:

Code:

(input(PIN_A1)) ? i = 1 : i = 0;


Error: Line 214(23,24): Expecting :

My compiler version is: 4.017

Can someone help me?
Thanks!!!
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Jul 25, 2008 9:24 am     Reply with quote

You syntax is wrong, it should be:
Code:
 i = (input(PIN_A1)) ? 1 : 0;

Several companies I've worked for don't allow the ?: construction because it often leads to difficult to read code and does not reduce the size of the generated code. The following code fragment does the same and is easier to read:
Code:
if (input(PIN_A1))
  i = 1;
else
  i = 0;
or in this particular case can even be optimized to:
Code:
i = input(PIN_A1);



As a side note: the compiler versions before v4.030 contain large numbers of bugs and I wouldn't use them.
rhaguiuda



Joined: 05 Sep 2007
Posts: 46
Location: Londrina - Brazil

View user's profile Send private message

PostPosted: Fri Jul 25, 2008 11:04 am     Reply with quote

Ckielstra, thanks very much.
The code works great now!
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