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

語法錯誤現在消失了,但我無法理解邏輯.... –