Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!clyde!cbatt!ihnp4!drutx!mtuxo!mtgzz!bds From: bds@mtgzz.UUCP Newsgroups: comp.lang.c Subject: Re: incrementing after a cast Message-ID: <2319@mtgzz.UUCP> Date: Fri, 5-Dec-86 10:12:23 EST Article-I.D.: mtgzz.2319 Posted: Fri Dec 5 10:12:23 1986 Date-Received: Sat, 6-Dec-86 03:21:49 EST References: <349@apple.UUCP> Distribution: net Organization: AT&T, Middletown NJ Lines: 29 Keywords: cast, increment, postincrement Summary: *(type)var is an lvalue In article <349@apple.UUCP>, kanner@apple.UUCP (Herbert Kanner) writes: > foo() > { > sometype L; > char *chp; > > L = *((sometype *) chp)++; > } > ... > Our problem arises with the allegation that K&R makes this construct > illegal. On page 214 (syntax summary), the only legal context for ++ > is given to be lvalue++, and (type-name) expression is a case of > expression which, according to that syntax, cannot be an lvalue. Your confusion comes, I believe, by assuming that precedence and grouping rules force one parse to the exclusion of all others (i.e. that the expression is parsed as *(((sometype *) chp)++) which is illegal). By parenthesising the expression: L = (*((sometype *) chp))++ Then using the rules on page 214 the parse is: expression : (type-name) expression lvalue : * expression expression : lvalue++ Note that this is the parse generated even without the parenthesis. Happily, it is the one you want.