[Top][All Lists]

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

Re: [avr-gcc-list] differences between "char *var" and "char var[]"

From: Tyler Hall
Subject: Re: [avr-gcc-list] differences between "char *var" and "char var[]"
Date: Sat, 19 Apr 2003 16:46:26 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.0.2) Gecko/20021216

I think I found a working solution after reading about some gcc extensions:

#define PTR2PSTR(s) (prog_uchar []) {(s)}
prog_char *g_array[] PROGMEM = {
   PTR2PSTR("first string"),
   PTR2PSTR("second string"),
   PTR2PSTR("another string"),

This causes 'g_array' to be a symbol in .progmem.data that contains 3 pointers (16 bits each). Each pointer happens to point to data also in the .progmem.data section, where we find the three separately defined strings. So maybe I need to bug the avrlibc folks to add this macro to pgmspace.h as it works outside the scope of functions.

Does anyone know if there was another way to tackle this?


Tyler Hall wrote:

If I do the following:

typedef char my_prog_char __attribute__ (( progmem ));
my_prog_char gMyProgString[] __attribute__ (( progmem )) = "XYZ";

The initial "XYZ" string will properly be thrown into the .progmem.data section, which merges to the .text section. But if I instead do this:

typedef char my_prog_char __attribute__ (( progmem ));
my_prog_char *gMyProgString __attribute__ (( progmem )) = "XYZ";

The initial "XYZ" string will be thrown into the .data section.

My problem is that I want to do a typedef or something that let's me do this:

prog_string my_array[] = {

And each string gets the progmem attribute tagged to it. Unfortunately, I can't typedef prog_string like this:
typedef prog_char prog_string[] __attribute__ (( progmem ))

because the compiler complains about the open-ended array without initial value.

Can someone explain how gcc treats pointers to char (char *var) differently than arrays of char (char var[]) and why gcc treats initial data differently depending on which form is chosen?


avr-gcc-list mailing list

reply via email to

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