11

I am using AVR-GCC version 4.7.0, and when I attempt to create an array of strings in FLASH memory I get the error:

variable ‘menu’ must be const in order to be put into read-only section by means of ‘attribute((progmem))’

I am using this code:

const char menu0[] PROGMEM = "choice0";
const char menu1[] PROGMEM = "choice1";
const char menu2[] PROGMEM = "choice2";
const char menu3[] PROGMEM = "choice3";
const char menu4[] PROGMEM = "choice4";
const char menu5[] PROGMEM = "choice5";

const char *menu[] PROGMEM = {menu0, menu1, menu2, menu3, menu4, menu5};

I have already read Stack Overflow question C - how to use PROGMEM to store and read char array, but all the answers I see don't include the const keyword which makes me believe that they were written before it was needed.

How does one fix this problem?


const char * const menu[] PROGMEM = {menu0, menu1, menu2, menu3, menu4, menu5};

was the answer.

1
  • Try this: const char * const menu[]... Commented Jan 14, 2013 at 19:48

1 Answer 1

18

Try

const char* const menu[] PROGMEM...

Thus the array itself is constant, not a mutable array of const char* pointers, as it were in the original code.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, thank you. I actually just tried that, and was about to post the fact. Appreciations all around.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.