Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-lcc!rutgers!mit-eddie!husc6!necntc!encore!linus!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: comp.lang.c,comp.bugs.4bsd Subject: Re: lvalues and ++ Message-ID: <583@mcgill-vision.UUCP> Date: Sun, 21-Dec-86 01:19:51 EST Article-I.D.: mcgill-v.583 Posted: Sun Dec 21 01:19:51 1986 Date-Received: Mon, 22-Dec-86 18:40:31 EST References: <31da677c.809c@apollo.uucp> Organization: McGill University, Montreal Lines: 30 Xref: mnetor comp.lang.c:515 comp.bugs.4bsd:100 In article <31da677c.809c@apollo.uucp>, mishkin@apollo.uucp (Nathaniel Mishkin) writes: > I am having problems with the construct: > *((long *)p)++; > Some C compilers (e.g. the one sent with 4.3bsd) complain with the error: > illegal lhs of assignment operator > Other compilers seem to handle this correctly (incrementing by 4, by > the way). > Is this invalid C or is the 4.3bsd compiler broken? It is invalid C. A cast does not produce an lvalue. If you want this effect then try p = (whatever *) (1 + (long *)p) (if you want to use the value as well, try ((long *)(p=(whatever *)(1+(long *)p)))[-1] -- yech.) As someone on comp.lang.c pointed out when this question came up a while ago (it is one of the periodic questions), any compiler that "handle[s] this correctly" is broken twice - once for accepting it and again for modifying p (since "(long *)p" is a temporary, so the ++ should change the temporary, which will then get thrown away). der Mouse USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!mcgill-vision!mouse think!mosart!mcgill-vision!mouse Europe: mcvax!decvax!utcsri!mcgill-vision!mouse ARPAnet: think!mosart!mcgill-vision!mouse@harvard.harvard.edu