我正在使用AVR-GCC版本4.7.0,当我尝试在FLASH内存中创建一个字符串数组时,我得到错误:
变量'menu'必须是const才能通过' attribute((progmem))' 进入只读部分
我正在使用此代码:
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};
Run Code Online (Sandbox Code Playgroud)
我已经阅读了Stack Overflow问题C - 如何使用PROGMEM存储和读取char数组,但我看到的所有答案都没有包含const关键字,这让我相信它们是在需要之前编写的.
如何解决这个问题?
const char * const menu[] PROGMEM = {menu0, menu1, menu2, menu3, menu4, menu5};
Run Code Online (Sandbox Code Playgroud)
是答案.