🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9674

forcing evaluation order (was "Expression Sequencing Query")

#9674
From: Tom Stockfisch
Date: Wed, 22 Oct 1986 20:09
35 lines
1954 bytes
In article <2809@watmath.UUCP> rbutterworth@watmath.UUCP (Ray Butterworth) writes:
>> The ANSI C draft standard provides the unary plus operator for coercing
>> evaluation order.  Thus
>>     a = +(b + c) + +(d) ;
>> should force the sum of b+c to be calculated and added to d....
>
>Does X3J11 (or any other C "standard") say anything about the
>order of evaluation of (possibly redundant) cast expressions?
>
>e.g.      ( ((double)(a+b)) + ((double)(c+d)) )
>
>where a, b, c, and d may or may not be type (double)?
>
>It would certainly be prettier than the unary " +" operator,
>and certainly more obvious that the programmer really did want
>the given grouping.

I find the c a s t much harder to read.
I much prefer to have all alphanumeric
objects in an expression be variables,
and all operators to be
non-alphanumeric.  In addition, for
numeric expressions, the fewer the
parentheses the better, since they tend
to be profuse.  I don't understand why
you think the intent is clearer with the
cast.  The sole purpose (I think) of
unary plus is to force evaluation order,
whereas casts are normally used for type
conversion.  In your example, if a, b,
c, and d were all doubles, I would be
very confused about the purpose of c a s
t i n g them to double.

-- Tom Stockfisch, UCSD Chemistry
Technical Details
Message-ID: <413@sdchema.sdchem.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!sri-spam!nike!ucbcad!ucbvax!sdcsvax!net1!sdchem!tps
References: <4711@brl-smoke.ARPA> <2809@watmath.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!rutgers!sri-spam!nike!ucbcad!ucbvax!sdcsvax!net1!sdchem!tps
From: tps@sdchem.UUCP (Tom Stockfisch)
Newsgroups: net.lang.c
Subject: forcing evaluation order (was "Expression Sequencing Query")
Message-ID: <413@sdchema.sdchem.UUCP>
Date: Wed, 22-Oct-86 15:09:34 EST
Article-I.D.: sdchema.413
Posted: Wed Oct 22 15:09:34 1986
Date-Received: Thu, 30-Oct-86 06:31:38 EST
References: <4711@brl-smoke.ARPA> <2809@watmath.UUCP>
Sender: news@sdchem.UUCP
Reply-To: tps@sdchemf.UUCP (Tom Stockfisch)
Organization: UC San Diego
Lines: 35