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

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

RE: [avr-gcc-list] array of string pointers in progmem


From: Ralph Stickley
Subject: RE: [avr-gcc-list] array of string pointers in progmem
Date: Mon, 29 Apr 2002 14:47:42 -0400

This seemed to compile :)  maybe somebody can check this to see if it does
what the map file says it does...

HTH..Good luck...
==========

#include <io.h>
#include "pgmspace.h"


   PROGMEM int   aaa         = 11;
   PROGMEM int   bbb[ 2 ]    = { 1, 2 };
   PROGMEM char  ccc[ 2 ]    = { 'a', 'b' };  // allocates 2 bytes

   PROGMEM char  ddd[6]      = "test1";       // allocates 6 bytes in
program memory space (w/trailing zeros ?)

   PROGMEM char *eee[ 2 ]    = { "test", "memory" };   // allocates 2
two-byte pointers in program memory, array data is in data space

   PROGMEM char  fff[ 2 ][6] = { "s1", "test3" }; // allocates 12 bytes in
program memory space

typedef unsigned char  u08;

int main( void )
{
           char y[ 6 ];
           int len;
           int i;

     for ( i = 0; i < 2; i++ )
     {
        len = strlen_P(  &fff[ i ][ 0 ] );
        memcpy_P( &y[ 0 ], &fff[ i ][ 0 ], len );
     }

     while( 1 );
}

... these show up in map file (and who sorts this stuff anyhow ?) as:

 .progmem.data  0x000000d6       0x1e gcctest1.o
                0x000000e4                eee
                0x000000e8                fff
                0x000000d6                aaa
                0x000000de                ddd
                0x000000d8                bbb
                0x000000dc                ccc
                0x000000f4                .=ALIGN(0x2)

> ----------
> From:         Peter N Lewis[SMTP:address@hidden
> Sent:         Saturday, April 27, 2002 11:45 PM
> To:   address@hidden
> Subject:      Re: [avr-gcc-list] array of string pointers in progmem
> 
> At 23:40 -0700 28/4/02, xol wrote:
> >I want to do following
> >Create array of pointers to strings in program memory. Strings also 
> >must be in program memory.
> >
> >I try following:
> >PGM_P str_table[] PROGMEM = { "ERROR", "OK" };
> >
> >I get
> >
> >00000026 <str_table>:
> >   26:   61 00 67 00
> >
> >Contents of section .data:
> >  800060 01455252 4f52004f 4b00               .ERROR.OK.
> >
> >Compiler put pointers to prog memory but I can't make him to put string
> there.
> 
> The only solution I found is this one from 
> <http://ww2.tiki.ne.jp/~maro/AVR/old/tips.html>:
> 
> >I wish to put an array of strings into progmem. The only solution I found
> is
> >------
> >PROGMEM char pcStandard[] = "Standard";
> >PROGMEM char pcClass[] = "Class";
> >PROGMEM char pcVendor[] = "Vendor";
> >PROGMEM char pcReserved[] = "Reserved";
> >char * _NAME_USB_REQUEST_TYPE[] =
> >{pcStandard, pcClass, pcVendor, pcReserved };
> 
> It would seem that the PROGMEM attribute applies only to the 
> *variable* being defined.  So in your example, the variable str_table 
> points into progmem.  But the contents of that variable in progmem 
> are string pointers which point in to RAM.
> 
> In order for those strings to be placed in progmem, it appears there 
> has to be an associated variable with the PROGMEM attribute.
> 
> Perhaps someone has an alternative idea?
>     Peter.
> -- 
> <http://www.interarchy.com/>  <ftp://ftp.interarchy.com/interarchy.hqx>
> avr-gcc-list at http://avr1.org
> 
avr-gcc-list at http://avr1.org



reply via email to

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