[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] initial values in structs

From: Tyler Hall
Subject: [avr-gcc-list] initial values in structs
Date: Sat, 19 Apr 2003 00:41:44 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.0.2) Gecko/20021216

I've read through the avrlibc docs and FAQ, and I see a "possible" solution to this, but it's pretty messy

To do something like this outside the scope of a function (all values are constant):
typedef struct {
   prog_char *name;
   prog_char properties;
   prog_char othervar;
   void (*func) (void);
} mystruct_type;

mystruct_type g_mystruct[] PROGMEM = {
   { "first_name", PROPERTY_A, 0x34, myfunc1 },
   { "second_name", PROPERTY_B, 0x67, myfunc2 }

will cause the g_mystruct symbol to point to flash addr space because PROGMEM puts the symbol and it's immediatly initialized contents into another section. But the "string" instantiation will still get copied to RAM and the address of that string is what's kept in the flash as a member of the struct.

Now I know that if I'm in the scope of a function I can do this:

mystruct_type local_mystruct[] PROGMEM = {
   { PSTR("first_name"), blah blah blah },
   { PSTR("second_name"), blah blah blah }

but the definition of PSTR won't work outside the scope of a function.

The only solution I've seen for this is to tag a symbol to each string and add the PROGMEM attrib to each one, then use the symbol in the struct initialization:

prog_char gString1[] PROGMEM = "firstname";
prog_char gString2[] PROGMEM = "secondname";

mystruct_type local_mystruct[] PROGMEM = {
   { gString1, blah blah blah },
   { gStrign2, blah blah blah }

Is that the only to do this? Can I apply __attrib__ to unnamed initializers or does gcc always have to put initializers in RAM space?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]