|
|
View previous topic :: View next topic |
Author |
Message |
coder Guest
|
Using constants in ternaries |
Posted: Fri Oct 03, 2008 6:31 pm |
|
|
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
|
|
Posted: Sat Oct 04, 2008 1:57 am |
|
|
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]); |
|
|
|
|
|
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
|