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

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

Re: [avr-gcc-list] invalid use of non-lvalue array


From: E . Weddington
Subject: Re: [avr-gcc-list] invalid use of non-lvalue array
Date: Wed, 1 Oct 2003 19:13:08 GMT

> I don't think that addresses the problem.
> 
> I can easily reproduce this. The only way I could work 
around it was
> with this hack:
> 
> -- begin example --
> #include <stdio.h>
> #include <avr/pgmspace.h>
> 
> int dummy_putchar (char c) { return 0; }
> 
> #define fprintf_PSTR(fp, fmt, args...) ({   \
>     static char pfmt[] PROGMEM = fmt;       \
>     fprintf_P (fp, pfmt, ## args);          \
> })
> 
> int
> main (void)
> {
>     FILE *fp = fdevopen (dummy_putchar, NULL, 0);
> 
>     fprintf_PSTR (fp, "Hello World!\n");
> 
>     return 0;
> }
> -- end example --
> 
> And avr-objdump shows that the string went to .text:
> 
> Contents of section .data:
<snip> 
> 
> I wonder if it would make sense to wrap all the *_P 
functions like
> this. Then you wouldn't need to use PSTR at all.
> 
> Pros:
> 
>   - All *_P calls become cleaner. E.g, printf_P(PSTR
("foo")); becomes
>     printf_P("foo");
> 
>   - Works in C and C++.
> 
> Cons:
> 
>   - Is gcc smart enough to catch multiple copies of a 
string? A little
>     experiment just now shows it's not.

But wasn't this already the case? i.e., This isn't anything 
new introduced by your new method, right?

 
>   - Makes it impossible to pass a ptr to a fmt string.

Or for any other *_P function for that matter. It would 
make it impossible to pass any variable that's a pointer to 
a string in flash. It's only good for passing constant 
strings.

Hmmm. Bummer. :-/

Eric






reply via email to

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