🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9531

Re: Expression sequencing query

#9531
From: Chris Torek
Date: Thu, 09 Oct 1986 11:32
31 lines
1924 bytes
In article <160@geac.UUCP> len@geac.UUCP (Leonard Vanek) writes:
>... I agree that it is asking for trouble to mix
>side effects in with complicated expressions, [but] I still believe
>that it is a pity that C (even Ansi C) does not even let the
>programmer tell it what order is desired by the use of parentheses!
>To ignore parentheses in determining the evaluation order (i.e.
>(a+b)+c does not guarantee that a and b are added first) causes
>problems with round off errors, not just side effects -- and is
>totally counter-intuitive.

If you want `a+b' to be done first, then `result + c', use

	result = a + b;
	result += c;

The solution is trivial, and the `problem' is well documented.  To
those to whom parentheses directly determine order of evaluation,
I suppose this is indeed troublesome.  As for myself, I never expect
parentheses to do more than override default precedence, so it is
not `totally counter-intuitive' to me.  Even in Fortran I (where,
I believe, the language specification says that (A+B)+C is requires
doing A+B first, then result+C) I would write

	RESULT = A + B
	RESULT = RESULT + C

---if that were what I meant.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@mimsy.umd.edu
Technical Details
Message-ID: <3769@umcp-cs.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!umcp-cs!chris
References: <760@oakhill.UUCP> <111@titan.UUCP> <468@jc3b21.UUCP> <160@geac.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!mnetor!seismo!umcp-cs!chris
From: chris@umcp-cs.UUCP (Chris Torek)
Newsgroups: net.lang.c
Subject: Re: Expression sequencing query
Message-ID: <3769@umcp-cs.UUCP>
Date: Thu, 9-Oct-86 07:32:21 EDT
Article-I.D.: umcp-cs.3769
Posted: Thu Oct  9 07:32:21 1986
Date-Received: Fri, 10-Oct-86 01:28:23 EDT
References: <760@oakhill.UUCP> <111@titan.UUCP> <468@jc3b21.UUCP> <160@geac.UUCP>
Reply-To: chris@umcp-cs.UUCP (Chris Torek)
Distribution: net
Organization: University of Maryland, Dept. of Computer Sci.
Lines: 31