2013-01-14 46 views
8

我使用AVR-GCC 4.7.0版和字符串数组,当我试图创建FLASH存储器字符串数组我得到的错误:存储在闪存与PROGMEM在Arduino的

variable ‘menu’ must be const in order to be put into read-only section by means of ‘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}; 

我已经看过堆栈溢出问题C - how to use PROGMEM to store and read char array,但我看到的答案不包括const关键字这使我相信这是需要之前,他们写的。

如何解决这个问题?


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

他回答。

+0

试试这个:'const char * const menu [] ...' – imreal

回答

16

尝试

const char* const menu[] PROGMEM... 

因此数组本身是恒定的,而不是const char*指针一个可变的数组,因为它是在原来的代码。

+0

是的,谢谢。我其实只是试过了,而且即将公布事实。赞赏全部。 – favilo

+0

语法错误现在消失了,但我无法理解逻辑.... –