简体   繁体   English

存储在闪存中的字符串数组,其中包含Arduino中的PROGMEM

[英]An array of strings stored in flash with PROGMEM in Arduino

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: 我正在使用AVR-GCC版本4.7.0,当我尝试在FLASH内存中创建一个字符串数组时,我得到错误:

variable 'menu' must be const in order to be put into read-only section by means of ' attribute ((progmem))' 变量'menu'必须是const才能通过' 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. 我已经阅读了Stack Overflow问题C - 如何使用PROGMEM来存储和读取char数组 ,但我看到的所有答案都没有包含const关键字,这让我相信它们是在需要之前编写的。

How does one fix this problem? 如何解决这个问题?


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

was the answer. 是答案。

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. 因此,数组本身是常量,而不是const char*指针的可变数组,就像在原始代码中一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM