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

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

Re: [avr-gcc-list] Defining global PSTR()s


From: Tyler Hall
Subject: Re: [avr-gcc-list] Defining global PSTR()s
Date: Thu, 5 Jun 2003 20:47:58 -0700 (PDT)

Hi, I posted the same question two months ago and
solved it myself the next day. After doing major
research into the memory sections I ended up with the
following. In short, what you're looking for is this:

prog_char main_menu[] PROGMEM = "Some text here";

In detail, what the PSTR macro is trying to do is
allocate some global memory outside the scope of the
stack (hence 'static'), then apply the __progmem__
attribute to this memory, declare an initial value for
that newly allocated memory, then finally return the
address (within the .progmem section) to that memory
region. This address is really the initial value to
the main_menu variable.

This entire operation is done within it's own scope
(inside its own {}'s) as a good rule of thumb for
macros that define code. Unfortunately it doesn't make
sense outside of the scope of a function, where you
are only allowed to state global declarations and
their initial values (no {}'s allowed). So to make it
work just do the same thing the macro does, without
the {}'s and with out the static keyword.

Maybe someone on the avr-libc team can define a GPSTR
macro that is intended for global variables.

Tyler

--- Hermann Kraus <address@hidden> wrote:
> Hello!
> 
> I have a problem when it try to define something
> like this as a global 
> variable:
> PGM_P main_menu = PSTR("Some text here");
> 
> The preprocessor converts it to(without the
> newlines, of course):
> const prog_char * main_menu = ({static char __c[] 
> __attribute__((__progmem__)) = ("Some text here");
> __c;});
> 
> The compiler's output is:
> 
> avr-gcc -c -save-temps -g -O2 -funsigned-char
> -funsigned-bitfields -fpack- 
> struct -fshort-enums -Wall -Wstrict-prototypes
> -Werror -Wa,-ahlms=led.lst - 
> mmcu=atmega16 -I. led.c -o led.o
> led.c:32: error: braced-group within expression
> allowed only inside a 
> function
> led.c:32: warning: type defaults to `int' in
> declaration of `__c'
> led.c:32: warning: data definition has no type or
> storage class
> led.c:32: error: parse error before '}' token
> make: *** [led.o] Error 1
> 
> As soon as I put in any functions the compiler
> doesn't complain anymore, 
> but it is not globaly accessible.
> 
> Now my questions:
> 1. Is this really the behavior the PSTR() macro
> should have???
> 2. How do I work around it? For the moment I'm using
> an inline function 
> that returns the pointer but the might be a better
> soulution.
> 
> Hermann
> 
> P.S.: I'm using avr-gcc (GCC) 3.3 20030310
> (prerelease)
> 
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list



reply via email to

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