Path: utzoo!attcan!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!rutgers!rochester!kodak!ektools!randolph From: randolph@ektools.UUCP (Gary L. Randolph) Newsgroups: comp.lang.c Subject: Re: Lvalues and casts Message-ID: <1912@ektools.UUCP> Date: 24 May 89 18:32:37 GMT References: <847@tub.UUCP> <1989May23.225818.9602@utzoo.uucp> Sender: randolph@ektools (Gary L. Randolph) Reply-To: randolph@ektools.UUCP (Gary L. Randolph) Organization: Eastman Kodak, Dept. 47, Rochester NY Lines: 38 In article <1989May23.225818.9602@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: >In article <847@tub.UUCP> net@tub.UUCP (Oliver Laumann) writes: >> (int *)cp = ip; >> >>The PCC, however, says "illegal lvalue in assignment". Is this legal >>C, i.e. is the result of a cast really an lvalue? > >No. Many compilers have accepted it, historically, but it has never >been legal C and it is not legal ANSI C. It is my understanding that all of the answers (similar to this one) are correct, but I have an extension to the original question. I have used casts on the LHS of assignment, but without actually assigning to the cast. Example: func(data, semaphore) char* data; char semaphore; { if (semaphore=='a') *(int *)data = 22; else if (semaphore=='b') *(float *)data = 64; . . . } Now the user of func() has supplied a pointer to some type, not necessarily a char. semaphore is used to determine the type of pointer func() actually received. The location pointed to by data is then modified as it is a legal lvalue. I believe this to be a typical use of the abused generic pointer, char*. I would, of course, use void* if I were using a dpANSI compiler. It is my understanding that using casts on the LHS of assignment in this way is fully portable. Right??? Gary