Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!mailrus!cornell!uw-beaver!uw-june!ka From: ka@june.cs.washington.edu (Kenneth Almquist) Newsgroups: comp.lang.c Subject: Re: Lvalues and casts Message-ID: <8322@june.cs.washington.edu> Date: 23 May 89 18:23:08 GMT References: <847@tub.UUCP> Organization: U of Washington, Computer Science, Seattle Lines: 18 net@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