Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: incrementing after a cast Message-ID: <4674@mimsy.UUCP> Date: Sat, 6-Dec-86 04:13:52 EST Article-I.D.: mimsy.4674 Posted: Sat Dec 6 04:13:52 1986 Date-Received: Sun, 7-Dec-86 03:31:44 EST References: <349@apple.UUCP> <2319@mtgzz.UUCP> Distribution: net Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 40 Keywords: cast, increment, postincrement >In article <349@apple.UUCP> kanner@apple.UUCP (Herbert Kanner) writes: >> L = *((sometype *) chp)++; [is illegal---correct] In article <2319@mtgzz.UUCP> bds@mtgzz.UUCP writes: >Your confusion comes, I believe, by assuming that precedence and >grouping rules force one parse to the exclusion of all others That is a reasonable assumption, for they do. >By parenthesising the expression: > > L = (*((sometype *) chp))++ This is indeed legal. It is also not what was written, and not what was desired. >Note that this is the parse generated even without the parenthesis. No: casts and `++' have higher precedence than `*'. The construct is semantically illegal, but the compiler will not alter it because of this. Incidentally, with a more concrete example: int L; char *cp; L = (*(int *)cp)++; treats `cp' as though it were a pointer to an integer, obtains the integer to which that points, copies that value into L, then increments the integer to which that points. The code generated is roughly: mov cp,reg mov *reg,L add #1,*reg -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) UUCP: seismo!mimsy!chris ARPA/CSNet: chris@mimsy.umd.edu