avr-chat
[Top][All Lists]
Advanced

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

[avr-chat] pgmspace with arrays of structs with strings


From: neil
Subject: [avr-chat] pgmspace with arrays of structs with strings
Date: Fri, 29 Apr 2011 17:27:04 +1200
User-agent: Mutt/1.5.18 (2008-05-17)

Can structs be kept in program memory even when those structs include strings?

In this example:

    #include <avr/pgmspace.h>
    
    typedef struct
    {
      uint8_t  x:4, y:4;
      char     *name;
    }
    Pin;
    
    //#define  P(str)  PSTR(str)
    #define  P(str)  str
    
    Pin  PROGMEM  pin[] =
    {
      { 0,  0, P("PC6")},
      { 0,  1, P("PD0")},
    };
    
    int main( void)
    {
      while ( 1)
      {
      }
    }

.. if "PROGMEM" is omitted then I get:

    flash: 112 bytes
    RAM:   14 bytes

When "PROGMEM" is left in ( as above) I get:

    flash: 112 bytes
    RAM:   8 bytes

..so the "x" and "y" parts of the struct along with the 16-bit string pointers
are now in program memory yet the strings ( 2 * (strlen("PC6") + 1)) still
consume RAM.  When I define "P" as an alias for "PSTR" I get:

    example.c:16: error: braced-group within expression allowed only inside a 
function
    example.c:17: error: braced-group within expression allowed only inside a 
function
    make: *** [example.o] Error 1

Is there some way that the whole structure can be kept in program memory?

Thanks in advance,

- neil




reply via email to

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