Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!houxm!whuxl!whuxlm!akgua!gatech!seismo!mcvax!enea!erix!erisun!hans From: hans@erisun.UUCP Newsgroups: net.unix-wizards Subject: Re: C compiler implements wrong semantics Message-ID: <466@erisun.UUCP> Date: Tue, 4-Feb-86 07:13:27 EST Article-I.D.: erisun.466 Posted: Tue Feb 4 07:13:27 1986 Date-Received: Fri, 7-Feb-86 21:15:37 EST References: <2147@brl-tgr.ARPA> Reply-To: hans@erisun.UUCP (Hans Albertsson) Organization: Ericsson Information Systems AB, Sundbyberg, Sweden Lines: 35 This has no doubt been multiply reiterated over the years, but here goes again: The result of the statement b = ( a++ + a ); is not defined by the semantics of C. Evaluation of subexpressions may be performed in any order and, specifically, code which depends on subexpression evaluation order is erroneous. This is one trait C shares with most sequential assignment based procedural languages. As an aside, there is an operator, ',' , which defines evaluation order and not much else, and there are the && and || operators, of course, but these destroy arithmetic values in their course of duty. The above statement could be written as b = ( ( b = a++ ), b += a ) to produce one particular evaluation order, or b = ( ( b = a ), b += a++ ) for the other order, but neither appears to have any advantages compared to their sequential statement forms, b = a; b = a; b += ++a; b += a++; which are semantically indisputable. -- Two's complement, but three's an int. Hans Albertsson EIS, USENET/uucp: {decvax,philabs}!mcvax!enea!erix!erisun!hans