Lvalues and casts
Kenneth Almquist
ka at june.cs.washington.edu
Wed May 24 04:23:08 AEST 1989
net at tub.UUCP (Oliver Laumann) asks:
> (int *)cp = ip;
>
> Is this legal C, i.e. is the result of a cast really an lvalue?
No.
On most machines, converting from a character pointer to an integer
pointer does not generate any executable code, so the cast can be
discarded early on. If the compiler tests for valid lvalues after it
discards casts which don't generate code, it will fail to detect that
the left hand side of the assignment is not an lvalue.
In the case of gcc, the fact that the results of a cast can be used
as an lvalue is a feature rather than a bug. This feature can be
disabled by compiling with the -pedantic option.
Kenneth Almquist
More information about the Comp.lang.c
mailing list