Casting the lvalue
Wayne Throop
throopw at sheol.UUCP
Sun Mar 11 09:49:33 AEST 1990
> From: henry at utzoo.uucp (Henry Spencer)
>> From: psm at manta.nosc.mil.UUCP (Scot Mcintosh)
>>The following seems to be illegal...
>>(int)array[1] = 5;
>>[...]Question: why is [..this..] illegal...
> Why should it be legal? What does it *mean*?
What Henry left out was that a cast is a conversion of datatype. It is
a commonly made mistake to suppose that casts change the type of an
object or value without any conversion action sometimes. This is never
the case. This has never been the case. Once upon a time, a family of
sloppy compilers left the result of a cast an lvalue in some
circumstances. Some users of this family of compilers have taken this
unfortunate circumstance as Natural Law, ignoring or never obtaining
lint's warnings to the contrary. Similar to the naive person who takes
the local mores of that person's tribe as Natural Law.
Thus, the expression ((int)array[1] = 5) is as meaningless in C
as the expression ((a+3) = 5). Thus, Henry's amazement. After
all, as he said...
What does it *mean*?
--
Wayne Throop <backbone>!mcnc!rti!sheol!throopw or sheol!throopw at rti.rti.org
More information about the Comp.lang.c
mailing list