🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9410

Re: Re: Expression sequencing query

#9410
From: Mike Meyer
Date: Fri, 26 Sep 1986 09:27
44 lines
2295 bytes
In article <353@cullvax.UUCP> drw@cullvax.UUCP (Dale Worley) writes:
>> In article <760@oakhill.UUCP> tomc@oakhill.UUCP (Tom Cunningham) writes:
>> >	/* a = b + b + b */
>> >	a = ((b=1),b) + ((b=2),b) + ((b=3),b)
>> >
>> >I expected the result to be 6.  With the Microsoft C compiler and the
>> >compiler on the Sun 3, the result is 9.  Apparently the parenthetical
>> >assignments are all getting done before the comma and addition.  Any
>> >thoughts on this?
>
>Harbison&Steele (7.11) makes it clear that an implementation must
>evaluate one argument of a binary operator completely before starting
>evaluation of the other argument.  Thus, the result should be 6.  I
>don't know what the ANSI standard says.

My reading of the ANSI hardcopy is that it doesn't say. I thought H&S
was a description, not a definition.

>Dec VAX Ultrix gives 9.

As do VAX 4.2 and 4.3.

>Lattice C 3.00 for MS-DOS gives 7!!!  (Yes, that's "7", not a typo!)

Some messy - and almost believable - arguments can be made that the
value of that expression is "implementation dependent". Rather than do
that, I'll just point out that *ANY* time++ you have a single
statement that changes a variable, then uses the variable in a
different place, you're asking for trouble. For that particular
expression, I'd expect the following, with increasing surprise as you
move down the list:

	6
	3, 9
	4, 5, 7, 8
	other integers representable on the machine
	NANs of various flavors
	dropped cores.

	<mike


++ Except for those cases that are in different operands of a logical
operator, as the evaluation order on those is known.
Technical Details
Message-ID: <1340@jade.BERKELEY.EDU>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!ihnp4!qantel!lll-lcc!lll-crg!nike!ucbcad!ucbvax!jade!eris!mwm
References: <760@oakhill.UUCP> <111@titan.UUCP> <353@cullvax.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!ihnp4!qantel!lll-lcc!lll-crg!nike!ucbcad!ucbvax!jade!eris!mwm
From: mwm@eris.berkeley.edu (Mike Meyer)
Newsgroups: net.lang.c
Subject: Re: Re: Expression sequencing query
Message-ID: <1340@jade.BERKELEY.EDU>
Date: Fri, 26-Sep-86 05:27:59 EDT
Article-I.D.: jade.1340
Posted: Fri Sep 26 05:27:59 1986
Date-Received: Tue, 30-Sep-86 06:33:35 EDT
References: <760@oakhill.UUCP> <111@titan.UUCP> <353@cullvax.UUCP>
Sender: usenet@jade.BERKELEY.EDU
Reply-To: mwm@eris.UUCP (Mike Meyer)
Distribution: net
Organization: Missionaria Phonibalonica
Lines: 44