Pages: [1]   Go Down
Author Topic: Static initialization of PGM_P in struct  (Read 740 times)
0 Members and 1 Guest are viewing this topic.
Piemonte, Italia
Offline Offline
Jr. Member
**
Karma: 1
Posts: 65
Just a brick in the wall
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Suppose I have a struct like:

Code:
struct SomeStruct {
PGM_P name;
// Other fields...
};


I would like to write:

Code:
SomeStruct s[] = {
{PSTR ("One")},
{PSTR ("Two")}
};


Unfortunately the compiler refuses to compile this. I can work it around with something like:

Code:
const char oneStr[] PROGMEM = "One";

SomeStruct s[] = {
{oneStr},
// ...
};

But it's a bit too complicated for my taste. Is there a way to put the strings inside the array declaration?

Thanks in advance!
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4016
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think that you should make the struct definition normally then put the array of structs into progmem with a progmem pointer to the array. Then structs and members can be addressed as offsets to the pointer in the normal manner.

Logged

Examples can be found in your IDE.

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_rom_array
Logged

Piemonte, Italia
Offline Offline
Jr. Member
**
Karma: 1
Posts: 65
Just a brick in the wall
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, it seems there is no other way smiley-sad. Thanks WizenedEE.
« Last Edit: July 30, 2012, 02:36:22 am by SukkoPera » Logged

Pages: [1]   Go Up
Jump to: