Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 5.1sysV68-beta 6/6/85; site necis.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!wanginst!vaxine!encore!necis!yde From: yde@necis.UUCP (David Elins ext. 220) Newsgroups: net.lang.c Subject: Re: *p++ = *p results? Message-ID: <258@necis.UUCP> Date: Mon, 24-Mar-86 11:43:23 EST Article-I.D.: necis.258 Posted: Mon Mar 24 11:43:23 1986 Date-Received: Thu, 27-Mar-86 07:24:50 EST References: <312@imagen.UUCP> Reply-To: yde@necis.UUCP (David Elins ext. 220) Distribution: net Organization: NEC Information Systems Lines: 34 In article <312@imagen.UUCP> kevin@imagen.UUCP (Kevin L. Malloy) writes: >In the statement *p++ = *p; what will be the result? My understanding, confirmed by lint, is that this is an ambiguous statement. (lint said "warning: p evaluation order undefined") The value of the expression p++ is p. Therefore the value of the expression *p++ is "the thing pointed to by p". The side effect of postincrement is that the contents of p are incremented AFTER the expression is evaluated. The real ambiguity is that C does not specify in which order the sides of an assignment operator (or any operator) get evaluated (c.f. K&R p. 49). If the left side is evaluated first then because of the postincrementing side effect, the value of the right side would be the next item after the one p pointed to before the statement was executed, and the outcome would be that p points to the next item, and that the original item and its successor (the next item) have identical values, the value of the original "next item". If the right side is evaluated first when it is all over, p will still point to the next item but now the two items will maintain their original values. I tried a little test program (which produced the lint message) on both System III and System V. The two systems, as implemented here gave different results: system V evaluated the left side first, system III did the right side first. Boy, this stuff is hard to write about in a clear fashion. Maybe that is why I am a programmer and not a writer (:-). david