Go Down

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

SukkoPera

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[] = {
{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!

GoForSmoke

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

WizenedEE

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

SukkoPera

#3
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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy