avr-chat
[Top][All Lists]
Advanced

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

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


From: neil
Subject: Re: [avr-chat] pgmspace with arrays of structs with strings
Date: Sun, 01 May 2011 10:47:21 +1200
User-agent: Mutt/1.5.18 (2008-05-17)

> > Can structs be kept in program memory even when those structs include 
> > strings?
> Try defining and initializing your strings (in program memory) at the top 
> level, i.e. outside of the structure definition, and then using their names 
> to initialize the structure.

Thanks for this suggestion.  It certainly works:

    #include <avr/pgmspace.h>

    typedef struct
    {
      uint8_t  x:4, y:4;
      char     *name;
    }
    Pin;

    char  PROGMEM  _PC6[] = "PC6";
    char  PROGMEM  _PD0[] = "PD0";

    Pin  PROGMEM  pin[] =
    {
      { 0,  0, _PC6},
      { 0,  1, _PD0},
    };

    int main( void)
    {
      while ( 1)
      {
      }
    }

Gives:

    flash: 90 bytes
    RAM:   0 bytes

Is there any way make it tidier ( without declaring identifiers like _PC6)?

- neil




reply via email to

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