generalized lvalues -- patch outline

Thomas Kunert kunert@physik.tu-dresden.de
Tue Nov 23 18:03:00 GMT 2004


Paul Koning wrote:
>>>>>>"Eric" == Eric Botcazou <ebotcazou@libertysurf.fr> writes:
> 
> 
>  >> The average C programmer would not have thought to use this
>  >> extension unless they just decided one day to try it or they
>  >> actually read the gcc documentation (which I know almost nobody
>  >> does).
> 
>  Eric> I disagree: *((int *)p)++ was accepted by virtually all the
>  Eric> good old compilers: GCC 2.x, Microsoft, Borland, Watcom.  This
>  Eric> is a natural idiom when you're manipulating images with
>  Eric> different color depths ...
> 
> ... or doing alignment-optimized copying.  I've seen this notation in
> our code, and I'm pretty sure the author didn't get it from the GCC
> docs.  It's a natural thing to write -- unless you ARE a language
> lawyer and understand the hairy details of precisely what is an lvalue
> and what is not.
> 

A union is the correct solution.

union {
    char* c;
    int* i;
    short* s;
} p;

*p.i++;

TK.




More information about the Gcc mailing list