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: Theodore A. Roth
Subject: RE: [avr-gcc-list] PSTR macro bug in C++
Date: Fri, 10 Sep 2004 13:58:35 -0700 (PDT)

On Fri, 10 Sep 2004, Dave Hylands wrote:

> 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.

Thanks Dave. That explanation gives me confidence that this is the right
approach. I'm going to add that last paragraph as a comment in the
header so that the casual reader will understand why we need to do the
apparently useless operations.

I'm going to commit the changes to HEAD and 1.0 now and close out this
bug.

>
> 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.

---
Ted Roth
PGP Key ID: 0x18F846E9
Jabber ID: address@hidden


reply via email to

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