Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!mcnc!ncsu!uvacs!edison!steinmetz!davidsen From: davidsen@steinmetz.UUCP (Davidsen) Newsgroups: net.lang.c Subject: Re: Casting a postdecrement operand Message-ID: <786@steinmetz.UUCP> Date: Thu, 12-Jun-86 12:52:03 EDT Article-I.D.: steinmet.786 Posted: Thu Jun 12 12:52:03 1986 Date-Received: Sun, 15-Jun-86 02:22:13 EDT References: <114@romp.UUCP> <2842@utcsri.UUCP> <1273@ulysses.UUCP> Reply-To: davidsen@kbsvax.UUCP (Davidsen) Organization: GE CRD, Schenectady, NY Lines: 42 In article <1273@ulysses.UUCP> jss@ulysses.UUCP writes: >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 The variable 'cbap' is a pointer. The cast '(struct abc *)' is a pointer cast. I can use '((struct abc *)cbap)' with indirects and subscripts and anywhere that I can use an Lvalue, so I really believe that the expression is legal. Now, as to being *portable*. There is some language in the X3J11 proposed standard about possible loss of information and non-portability when pointers are cast. This is why the 'void *' type was introduced (in part) to have a pointer which could hold any valid data address. However, there is no guarantee that when the address of one data type, however obtaining, is cast to a pointer to another data type that the result will be valid. If I recall correctly the term in use in X3J11 for stuff was "valid but non-portable". Sorry I can't remember for sure who said it. I hope this clarifies the question somewhat (it does in my mind, anyway). -- -bill davidsen ihnp4!seismo!rochester!steinmetz!--\ \ unirot ------------->---> crdos1!davidsen / sixhub ---------------------/ (davidsen@ge-crd.ARPA) "Stupidity, like virtue, is its own reward"