Tuesday, November 15, 2011

GCC 4: error: lvalue required as increment operand

If you are compiling C code with GCC 4.x version you might receive the error:

error: lvalue required as increment operand
But the code compiled flawlessly with older versions of GCC.

The problem lies in GCC 4 which is a little more picky about the code. So we need to fix the code. Here is an example of the problematic code:
void CopyFromFrame8900(void *Dest, unsigned int Size)
{
    *((unsigned int *)Dest)++ = ReadFrame8900();
}
And the fix for it:
void CopyFromFrame8900(void *Dest, unsigned int Size)
{
    *((unsigned int *)Dest) = ReadFrame8900();
    Dest = (void *)Dest + 1;
}

1 comment: