[Top][All Lists]

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

RE: [avr-gcc-list] Strings in flash

From: Ron
Subject: RE: [avr-gcc-list] Strings in flash
Date: Tue, 2 Aug 2005 19:01:30 +1000

I think I over-simplified my example. The actual structure looks like:

typedef struct
   int index;
   char* line1;
   char* line2;
   char* line3;
   char* line4;
   void (*func1)(void);
   void (*func1)(void);
   void (*func1)(void);

There are about 200 entries in this array of indexed structures, hence
the need for readability by having the initialisation for each entry
localised in its entirety.

I guess the problem is that C normally does not allow adorning the
string with some qualifier in declarations like my example:

        "The first text message"
        "The second"

I wonder if gcc could be altered so you could declare flash in the type
declaration, something like:

typedef struct
    PGM_P   text;

The compiler would need to take note of this and, as the data
declaration is scanned, instead of recording an address in ram, record
the address as where it actually is in flash along with dropping any
need for startup copy to ram. A user could then first extract the
structure and then use the associated text pointer, something like:

    EXAMPLE p;
    char text[30];
    memcpy_P(&p, &Example[i], sizeof(EXAMPLE)); 
    strcpy_P(text, Example[i].text);

A bit awkward I know. Only a suggestion for the gcc gurus. I think I
will sacrifice some flash and use the "char text[24]" declaration. At
least then everything is automatically stored in flash.


> -----Original Message-----
> From: address@hidden 
> [mailto:address@hidden 
> On Behalf Of Joerg Wunsch
> Sent: Monday, 1 August 2005 11:54 PM
> To: address@hidden
> Subject: Re: [avr-gcc-list] Strings in flash
> In article <address@hidden> you write:
> >However, when the strings are a variety of sizes, space is 
> wasted. Is 
> >there some way to declare the array instance so I can use the type 
> >definition one would normally use in ram, ie:
> It's even described in the FAQ:

Note that quite often, it's not even necessary to put both, the table
and the strings in ROM, as the string pointers in the table itself don't
waste much RAM.
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)

AVR-GCC-list mailing list

reply via email to

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