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 CCS Technical Support

Using constants in ternaries

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







Using constants in ternaries
PostPosted: Fri Oct 03, 2008 6:31 pm     Reply with quote

Hey,

I'm trying to get the following code to compile.

Code:

   char c;
   int bool = 1;
   const int constBool = 1;
   const char constArray[1] = {'a'};
   char array[1] = {'a'};

   c = (bool ? constArray : constArray)[0];


While trying to fix this problem, I noticed that the following code compiles. The variables are declared the same as above.

Code:

   c = (bool ? constArray : array)[0];
   c = (constBool ? constArray : constArray)[0];


I could move my arrays into RAM instead of ROM by not declaring them constant, but the arrays I'm working with are large, so I'd rather put them in ROM if possible. I'm also curious as to why this is occurring. Any help would be appreciated.

Thanks
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Oct 04, 2008 1:57 am     Reply with quote

Hello,

ROM arrays imply a special handling of the data, where a call to a read function is inserted in the code for each assignment. Pointers to an ROM array are not provided by CCS C in default CONST mode.

Your construct
Code:
c = (bool ? constArray : constArray)[0];

implies calculating a pointer, that is dereferenced afterwards. This doesn't work with ROM constants.

Regards,
Frank

P.S.

A construct using strings directly rather than pointers should work:
Code:
   c = (bool ? constArray[0] : constArray[0]);
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