String array - pointers copied to RAM

I am using the IAR C compiler for the Renesas M16C and have in my code a string array declared as

const unsigned char * TestResultString[NUM_LANGUAGES][3] = { { "PASS", "FAIL", "INCOMPLETE" }, }; (NUM_LANGUAGES is currently 1 but will be increased later)

When I examine the resultant code it puts the text in code space but the pointers are copied at runtime from code memory to RAM (into the FAR_I segment). They are never changed during program operation so this would seem to be unnecessary as the originals naturally remain where they were copied from.

As I expand the text this will eat away at my RAM so how can I change it so that it keeps the pointers located in code memory?

One way would be to make the array have a fixed size like this

const unsigned char TestResultString[NUM_LANGUAGES][3][11] = { { "PASS", "FAIL", "INCOMPLETE" }, };

but this is quite wasteful of code memory as some of them have wide variations in the lengths of their elements.

I'm sure it is quite simple but I can't figure out what it is.

Thanks for any advice.

Reply to
neilwarnock
Loading thread data ...

Is there a keyword 'code' in the IAR compiler?

Paul burke

Reply to
Paul Burke

const unsigned char * const TestResultString[NUM_LANGUAGES][3] = ...

your pointers were declared to point to const but not to be const themselves - you need to tell the compiler what you want.

yes, it is quite simple. yes, you can figure it out. and yes you can stare at this sort of thing for ages while missing the key.

Your welcome

Peter

Reply to
Peter Dickerson

You may try something like this:

const unsigned char TestResultString[] = { "PASS\0" "FAIL\0" "INCOMPLETE\0\0" };

There is only one array, and hence one pointer, regardless of how many strings you would have. Of course you'd need the code to traverse this array, but it is the usual tradeoff between code size and data size.

HTH, Vadim

Reply to
Vadim Borshchev

Peter,

Yes, that's it! Thanks for the reminder!

Neil

Reply to
neilwarnock

Paul,

No - there is no "code" keyword. I tried that approach already as I am more familiar with the Keil C51 which does (const char code * code XXX...) but as Peter suggested above it should be const char * const XXX...

Regards, Neil

Reply to
neilwarnock

Vadim,

Thanks for the suggestion. I have enough code space at the moment, the problem was RAM. I'll keep your suggestion in mind for later when code space does get tight - as it always does ;)

Neil

Reply to
neilwarnock

What 'above'? You should quote enough of whatever you are replying to so that the context is clear. Don't use the broken google mechanism (see below in my sig).

--
"If you want to post a followup via groups.google.com, don't use
 the broken "Reply" link at the bottom of the article.  Click on 
 "show options" at the top of the article, then click on the 
 "Reply" at the bottom of the article headers." - Keith Thompson
Reply to
CBFalconer

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.