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

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

Re: [avr-gcc-list] Initializers and prog_mem


From: larry barello
Subject: Re: [avr-gcc-list] Initializers and prog_mem
Date: Sun, 1 Jul 2001 09:58:12 -0700

You can't declare both a pointer and a string at the same time. It doesn't
make sense since the pointer is just a constant pointing to the string which
is also a constant.  That is what you are trying to do with:

char *foo = "bar";

foo is a pointer to the string bar.

You can, however, put anything you want into FLASH as individual items.
Note: things put into the FLASH memory need to be declared "const"
elsewhere.  I modified you example to put both the test structure and the
strings into FLASH memory.  Naturally, you will not be able to directly
access *anything*.  You will need to calculate offsets and read the flash
with one of the program memory access routines.  That isn't as terrible as
it sounds.

Cheers!

unsigned char func1(void);
unsigned char func2(void);

#define FLASH __attribute__ ((progmem))

char FLASH text1[] = "text1";    // Place string into FLASH
char FLASH text2[] = "text2";

 struct test_t {
     unsigned char (*fn)(void);
     const char  *str;        // NB Str is a const pointer to flash
 } FLASH tests[] = {    // Stuck data struct into flash as well
  {func1,text1},
  {func2,text2},
  {0,0}
 };

int main(void)
{
 return(1);
}
----- Original Message -----
From: "Jesper Hansen" <address@hidden>
To: "AVR GCC List" <address@hidden>
Sent: Saturday, June 30, 2001 3:09 PM
Subject: [avr-gcc-list] Initializers and prog_mem


> Hi !
>
> Have anybody succeded in allocation an array of strings in prog_mem ???
>
> Here's what I want to do :
>
> /////////////////////
> struct test_t {
>     uint8 (*fn)(void);
>     char *str;
> } tests[] = {
>  {func1,"text1"},
>  {func_2,"text2"},
>  {0,0}
> };
> //////////////
> I want the two texts to be allocated directly in the program memory.
> Not matter how I turn it around and try to use the prog_char type, I can't
> get it to work. GCC always complain about the initializers.
>
> Even this simple stuff won't work :
>
> prog_char *ss[] = {"aaa","bbb"};
>
> Which is actually obvious as the progmem attribute belongs to "*ss" and
not
> to "*ss[]".
> But how the *&/"#%! does I describe that ?
>
>
> /Jesper
>
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list
>




reply via email to

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