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

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

RE: [avr-gcc-list] PSTR macro bug in C++


From: Dave Hylands
Subject: RE: [avr-gcc-list] PSTR macro bug in C++
Date: Fri, 10 Sep 2004 13:43:09 -0700

Hi Ted,

>From the experiments I did (using your little test program - Thanks), it
seems that the C++ compiler has a problem with just the __c. And I think
I understand why.

Lets suppose that we use PSTR("Test"). In this case, the type returned
by __c is a prog_char[5] and not a prog_char *. While these are
compatible, they aren't the same thing (especially in C++). The type
returned by &__c[0] is a prog_char *, which explains why it works fine.

So I would be inclined to use one of these:

        #define PSTR(s) ({static prog_char __c[] = (s); &__c[0];})
        #define PSTR(s) ({static char __c[] PROGMEM = (s); &__c[0];})

Rather than one of these:

        #define PSTR(s) ({static prog_char __c[] = (s); (prog_char
*)__c;})
        #define PSTR(s) ({static char __c[] PROGMEM = (s); (prog_char
*)__c;})

All 4 of the above work in your test program and disassemble to the same
thing.

--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/ 



reply via email to

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