🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Joshua W. Knight Sat, 18 Oct 1986 04:10
Re: Expression Sequencing Query
#9609
Author: Joshua W. Knight
Date: Sat, 18 Oct 1986 04:10
19 lines
1259 bytes
There have been lots of lamentations about C not providing a way to
force evaluation order.  The original subject (with multiple "side
effect" assignments to the same variable) isn't really the issue here.
One legitimate concern is truncation and such in numerical calculations.
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. This is
probably less pleasing to the eye but, as has been pointed out before,
parentheses already have a meaning in C, and it is explicitly NOT one
that forces order of evaluation.

Of course I speak only for myself, not my employer.

			Josh Knight
			IBM T.J. Watson Research Center
josh@ibm.com, josh@yktvmh.BITNET
Re: Expression Sequencing Query
#9622
Author: Ray Butterworth
Date: Tue, 21 Oct 1986 14:01
18 lines
1300 bytes
> 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. This is
> probably less pleasing to the eye but, as has been pointed out before,
> parentheses already have a meaning in C, and it is explicitly NOT one
> that forces order of evaluation.

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.
forcing evaluation order (was "Expression Sequencing Query")
#9674
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads