String array - pointers copied to RAM

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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.


Re: String array - pointers copied to RAM
Quoted text here. Click to load it
Is there a keyword 'code' in the IAR compiler?

Paul burke

Re: String array - pointers copied to RAM
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


Re: String array - pointers copied to RAM
Quoted text here. Click to load it

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
We've slightly trimmed the long signature. Click to see the full one.
Re: String array - pointers copied to RAM
Quoted text here. Click to load it

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.


Quoted text here. Click to load it
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.

Quoted text here. Click to load it
Your welcome

Peter



Re: String array - pointers copied to RAM
Peter,

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

Neil


Re: String array - pointers copied to RAM

Quoted text here. Click to load it

You may try something like this:

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

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

Re: String array - pointers copied to RAM
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


Site Timeline