1.6.1 PROGMEM problem (using new syntax) [SOLVED]

i had working code from IDE 1.0x or maybe 1.5x fail on 1.6.1. i found the note about the PROGMEM syntax change in the forum topic on the 1.6.0 release, but that doesn’t solve the problem.

for simplicity i reduced the problem down to four lines of code:

#include <avr/pgmspace.h>

const char text1[] PROGMEM = "text 1";
const char text2[] PROGMEM = "text 2";

const char *textArray [] PROGMEM = { text1, text2 };

the error produced is: (thanks for the COPY ERROR MESSAGES function!)

sketch_mar20a.ino:6:26: error: variable 'textArray' must be const 
in order to be put into read-only section by means of '__attribute__((progmem))'

i tried obvious-seeming permutations, eg textArray [2], etc, but all generate the above error, or worse.

any hints?

PS: i assume i’ll have trouble getting the text back out to Serial.print() it, but i’ll tackle that second. is there new documentation yet on the new PROGMEM syntax changes?

const char *[b]const[/b] textArray [] PROGMEM = { text1, text2 };

That "const" between the star and textArray tells C that textArray itself is const. The first "const" before the star tells C that the object(s) being pointed to is/are const.

It helps to know / remember that const is actually left associative. The pointer part of textArray is variable. Try this…

#include <avr/pgmspace.h>

const char text1[] PROGMEM = "text 1";
const char text2[] PROGMEM = "text 2";

const char * const textArray [] PROGMEM = { text1, text2 };

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

This is not really a new progmem syntax for 1.6.1. The declarations that used to "work" in the past were actually incorrect.
The new avr gcc compiler is more strict about what it will accept.
The adruino progmem page was updated to show the proper progmem syntax.

(scroll down a bit and you will see an example that is just like what you are needing)

The correct declaration will work on older compiler tools as well as the newer tools.

The reason it is failing is that the the declaration needs to declare that not only is the array pointer itself const but
it also points to const data.

--- bill

christop:
That “const” between the star and textArray tells C that textArray itself is const. The first “const” before the star tells C that the object(s) being pointed to is/are const.

d’oh! of course! and…

bperrybap:
This is not really a new progmem syntax for 1.6.1. The declarations that used to “work” in the past were actually incorrect. The new avr gcc compiler is more strict about what it will accept.

but i preferred my sloppy compiler kidding. i’m an old programmer but the PROGMEM crock i rarely use… but y’all and CODING BADLY’s reply induce me to go rtfm on “new” compiler stuff. not a bad idea to do once in a while (just this week i am going through some older code where i wrote needlessly complex class declaration stuff, after actually READING the F.M. page, years later).

The reason it is failing is that the the declaration needs to declare that not only is the array pointer itself const but it also points to const data.

GOT IT. thanks! i wasn’t looking at it properly. thanks for the fast and informative replies!