10

AVR-GCC バージョン 4.7.0 を使用していますが、フラッシュ メモリに文字列の配列を作成しようとすると、次のエラーが発生します。

変数 'menu' は、'<strong>attribute((progmem))'</p> によって読み取り専用セクションに入れるために const でなければなりません

私はこのコードを使用しています:

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};

Stack Overflow question C - how to use PROGMEM to store and read char arrayを既に読んでいますが、表示されるすべての回答にはconstキーワードが含まれていないため、必要になる前に書かれたと信じています。

この問題をどのように解決しますか?


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

が答えでした。

4

1 に答える 1

17

試す

const char* const menu[] PROGMEM...

const char*したがって、元のコードのように、配列自体は定数であり、ポインターの変更可能な配列ではありません。

于 2013-01-14T19:48:00.280 に答える