🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9620

Re: Expression sequencing query

#9620
From: peters
Date: Mon, 20 Oct 1986 17:19
40 lines
2390 bytes
In article <brl-smok.4642> 00R0DHESI%bsu.csnet@CSNET-RELAY.ARPA (Rahul Dhesi) writes:
>Peter S. Shenkin <cubsvax!peters@columbia.ARPA> writes:
><In article <umcp-cs.3769> chris@umcp-cs.UUCP (Chris Torek) writes:
><<	result = a + b;
><<	result += c;
><...
><...I wish there were some way of forcing order of execution, to 
><this extent anyway, within a line.
>
>Try this:
>     {int t = a + b; result = t + c;}  /* note:  force evaluation order */

So many have replied to me on this subject, both here and by netmail, that
I'd like to point out publicly what someone reminded me of by mail.

The draft ANSI standard specifies that unary "+" guarantees that a
parenthesized expression following it will be evaluated without interleaving
or other change of order;  thus, using the example previously bandied about, 
the usage:
	a = +( (b=1), b ) + +( (b=4), b ) + +( (b=16), b )
will guarantee that a is given a value of 21.

I rather like this;  it allows the code writer to specify where he thinks
order of evaluation is important, and allows the compiler to optimize
the order where it's not. 

We now have the following comparison:
	Fortran: parentheses specify both precedence of operators and
	   order of evaluation of operators with equal precedence, even
	   when the operators are commutative;
	C:  parentheses specify only precedence of operators.  Commutative
	   operators can have their arguments evaluated in any order, but
	   the default order, which will be compiler-dependent, can be
	   overridden with the unary "+".

You guys are giving us numerical folks less and less excuse to keep using
Fortran (break my heart)....  'Nuff said?

Peter S. Shenkin	 Columbia Univ. Biology Dept., NY, NY  10027
{philabs,rna}!cubsvax!peters		cubsvax!peters@columbia.ARPA
Technical Details
Message-ID: <567@cubsvax.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!think!mit-eddie!genrad!decvax!decwrl!pyramid!prls!philabs!cmcl2!rna!cubsvax!peters
References: <brl-smok.4642>

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!caip!think!mit-eddie!genrad!decvax!decwrl!pyramid!prls!philabs!cmcl2!rna!cubsvax!peters
From: peters@cubsvax.UUCP
Newsgroups: net.lang.c
Subject: Re: Expression sequencing query
Message-ID: <567@cubsvax.UUCP>
Date: Mon, 20-Oct-86 13:19:16 EDT
Article-I.D.: cubsvax.567
Posted: Mon Oct 20 13:19:16 1986
Date-Received: Wed, 22-Oct-86 03:33:22 EDT
References: <brl-smok.4642>
Reply-To: peters@cubsvax.UUCP (Peter S. Shenkin)
Organization: Columbia Univ. Bio. CG Fac., NY
Lines: 40