Re: Code now doesn't compile (GCC 3 vs GCC 4)

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

 



Fernando Gomes wrote:
> This code that compiles with GCC 3.x now doesn’t compile with GCC 4.x,
> is it possible to change some compiler directive in order to make it
> work again without have to change all the code?

No.

> This is just a code
> snippet, we have lots of code where void* variables are explicitly
> casted to other type pointers like in this small example, and we have
> the same error on all of them (in this case is when we try to
> increment the value pointed by gpf, we also have errors on similar
> situations like assignments and decrements).

Sorry, this isn't going to work.  You're using a gcc extension known
as "generalize lvalues" which IIRC was removed in about 2004.

http://gcc.gnu.org/gcc-3.4/changes.html

"The cast-as-lvalue extension has been removed for C++ and deprecated
for C and Objective-C. In particular, code like this:

        int i;
        (char) i = 5;

or this:

        char *p;
        ((int *) p)++;


is no longer accepted for C++ and will not be accepted for C and
Objective-C in a future version."

Workarounds for this are in most cases pretty obvious.

We don't usually break backwards compatibility by deleting well-known
gcc extensions, but this one is so evil that it had to go.

Andrew.





> 
>             void * gfp;
> 
>             gpf = & ……..
> 
>             *((int *)gfp)++;
> 
> Error message:
> 
> error: lvalue required as increment operand



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux