Simple substitution for * ((unsigned short *)ptr)++ = XXXX ?

Andrew Haley aph@redhat.com
Thu Aug 19 10:33:00 GMT 2010


On 08/19/2010 08:21 AM, Pan ruochen wrote:

> This following statement fails in the latest gcc (4.3.3):
>  * ((unsigned short *)ptr)++ = XXXX;
> 
> The messages are: `lvalue required as increment operand'.
> It is really a very convenient way of saving to the current
> pointer and then moving the pointer forward or backward.
> 
> It is a little complex to replace the statement with
> 	* ((unsigned short *)ptr) = XXXX; ptr += sizeof(unsigned short);
> 
> Why gcc does not support the style?

Because it's not legal C.  We used to support it, but we stopped.

> And there is another simple
> substitution for that?

Not really.  IMO if you're going to do something like this, better to
spell it out.

Andrew.



More information about the Gcc-help mailing list