Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site ulysses.UUCP Path: utzoo!watmath!clyde!burl!ulysses!jss From: jss@ulysses.UUCP (Jerry Schwarz) Newsgroups: net.lang.c Subject: Re: Casting a postdecrement operand Message-ID: <1273@ulysses.UUCP> Date: Wed, 28-May-86 10:50:38 EDT Article-I.D.: ulysses.1273 Posted: Wed May 28 10:50:38 1986 Date-Received: Fri, 30-May-86 05:01:57 EDT References: <114@romp.UUCP> <2842@utcsri.UUCP> Organization: AT&T Bell Laboratories, Murray Hill Lines: 30 In article <114@romp.UUCP> lwh@romp.UUCP (lwh) writes: >My version of pcc on the IBM RT PC allows the following expression: > > ((struct abc *)cbap)++; > > >to increment cbap by 500. It appears that the ANSI standard doesn't say >anything about the legality of this syntax. "++" requires an lvalue. A cast produces a value but not an lvalue, so this is not legal in ANSI (or in K&R ) C. Jerry Schwarz Bell Labs, MH Comment: Many C compilers (especially those derived from pcc) have a tendency to "extend C by convenience". That is, they have an algorithm that generates code on correct C programs. They give an error message only when that algorithmn runs into trouble. On some illegal programs the algorithm doesn't run into any problems and so they generate code anyway. In this case, I guess that the compiler does not keep track of whether an expression is an lvalue in the "syntax" rather it detects it in the "semantics". In some circumstances it implements a cast applied to an "identifier" by changing the data structure to pretend that the "name" has the modified type. The combination of these two results in the behavior you observe.