This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/MSP430F47187: What is the most EFFICIENT way to create a string table in ROM?

Part Number: MSP430F47187

Tool/software: TI C/C++ Compiler

Hi all,

Apologies for this pretty simple question..... but I am not able to figure it out. What is the best way to create a message table in ROM?

The most obvious way is of course to use

const unsigned char MessageTable[N][K];

where N is the number of messages and K is the number of characters per message.

However that still leaves me with the task to create a pointer and point to this message table.

is it possible to create an array of constant pointers to constant characters?

Thank you and any help will be much appreciated.

Best regards

Aniruddha Phadnis

  • Please consider writing it this way ...

    const char *message_table[] = {
       "first message",
       "second message",
       "third message",
       /* ... */
       "last message"
    };

    Note this creates two input sections that need to allocated to ROM.  The table of pointers to strings, that begins with the symbol message_table, is in the input section .data:message_table.  The strings are in the input section ".const:.string.  It is likely that your linker command file ignores the subsection names (the part after the colon) and allocates both .data and .const to ROM.

    Thanks and regards,

    -George

  • George Mock said:
    Please consider writing it this way ...

    I think the original poster wanted a constant array of pointers to constant strings, in which case suggest use the following form which means the message_table array is placed in the .const rather than .data section:

    const char *const message_table[] = {
       "first message",
       "second message",
       "third message",
       /* ... */
       "last message"
    };

    [Placing message_table in the .const section allows it to be stored in the MSP430 flash, saving on RAM space for the .data section]