avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] array of structures with variables in flash


From: katreniak
Subject: Re: [avr-gcc-list] array of structures with variables in flash
Date: Fri, 10 Jun 2005 16:31:04 +0200
User-agent: Mutt/1.5.6+20040907i

> Oops! missed that. Thanks for pointing out. And how do i declare a 
> variable to be in 

You have to think the way the compiler does. Struct is just a bunch of
data. Accessing the member of a structure means looking to a memory
location incremented by the member offset. There is nothing like one
member in flash and another in ram. All members are just grouped
together.  You cannot have one member in ram and another in flash.  The
same way you cannot have 5th and 11th member of an array stored in code
and the rest in ram. 

> > This should work. (Althought I didn't try to compile it)
> >
> > char const name0[] PROGMEM = "name0";
> > char const param0[] PROGMEM = "par01 par02 par03";
> >
> > struct {
> >     PGM_P name;
> >     const uint8_t no_of_param;
> >     PGM_P parameters;
> >  } const command[256] PROGMEM = { {name0, 3, param0},  };
> 
> Got it. But is there a way so i don't have to initialize at the time of 
> declaration but later? I guess this would not be possible(?)

No. You have to initialize it as a static variable. You can try to use
the preprocesor and move it to a special file.

> but have to have had declared this earlier;
> 
> char const name0[] PROGMEM = "name0";
> char const param0[] PROGMEM = "par01 par02 par03";
> 
> In my code an array of 256 such structures, this is going to be a pain 
> and i just might run out of names to give! ;-)

Don't worry. It is not very confortable but you can live with it.
I didn't find any workaround here.

> And can i have a structure like the above with members located in 
> different locations? For example, the variable "no_of_param" located in 
> RAM while the other 2 are located in flash?.
> Maybe i should rather have a pointer located in flash to a global 
> variable located in RAM?

Or you can move it into a separe array of structures (or just array of
integers) stored in ram. 

> 
> Yes, but i wanted to know how i do it for the stucture which has no name 
> as above. Stupid doubt i guess... All i had to do was give the 
> structure a name like "command_proto".

You can use the same name for the structure name and for a variable
instace. Structure names have their own dedicated namespace.

struct my_structure {
  int a,b;
 };

static struct my_structure my_structure;

 Brano

-- 
Branislav Katreniak
mailto: address@hidden




reply via email to

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