Go Down

Topic: Static initialization of PGM_P in struct (Read 1 time) previous topic - next topic


Suppose I have a struct like:

Code: [Select]
struct SomeStruct {
PGM_P name;
// Other fields...

I would like to write:

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

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

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

SomeStruct s[] = {
// ...

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!


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.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts




Jul 30, 2012, 09:34 am Last Edit: Jul 30, 2012, 09:36 am by SukkoPera Reason: 1
OK, it seems there is no other way :(. Thanks WizenedEE.

Go Up