Compilation error

Rob Landley rob at landley.net
Sat Sep 8 22:06:20 UTC 2007


On Saturday 08 September 2007 3:32:08 am kannappan at tesbv.com wrote:
> i have the following piece of code which gives compilation error (like
> lvalue requried...)  may be bug with the compiler
>
> uchar *s;
>
> *((ushort *)s)++ = val;

You told it to increment the value (which counts as writing to it), then 
overwrite that value with the assignment (which also counts as writing to 
it).  You have two conflicting writes to the same space in the same 
statement, and it's not _quite_ sure which order they should go in.  (Does 
the old value get incremented and then overwritten with the assignment?  Does 
the new value get assigned and then increment?)

Not legal C.

> if i change that to
>   *(ushort *)s = val;
>   s+=2;
>
> it works fine.

Well yes.  Now you're making it clear what order to do things in.

Since when is +=2 equivalent to ++?

Rob
-- 
"One of my most productive days was throwing away 1000 lines of code."
  - Ken Thompson.



More information about the uClibc mailing list