Expression sequencing query

Daniel R. Levy levy at ttrdc.UUCP
Wed Oct 15 13:12:30 AEST 1986


In article <559 at cubsvax.UUCP>, peters at cubsvax.UUCP (Peter S. Shenkin) writes:
>>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.
>>						...I never expect
>>parentheses to do more than override default precedence, so it is
>>not `totally counter-intuitive' to me.
>One of the attractions of C is its elegance and conciseness of expression;
>having to declare a variable only for the purpose of defining order of
>evaluation, even when the expression is extremely simple, is inelegant and 
>inconcise, and the requirement to do so can easily double the size (as measured 
>by the number of lines) of source code in numerical work where rounding error
>is significant and such order has to be thoroughly thought through.
>
>C wasn't originally designed for such applications, of course, but now that
>we're going to be able to do single-precision arithmetic across function
>calls there's going to be less and less reason to avoid using C;  unfortunately,
>this parentheses thing is going to remain one of them.
>I understand the reason for the accepted convention, and I accept that reason,
>but even if it's necessary it's a necessary evil;  let's not make a virtue
>out of it.  I wish there were some way of forcing order of execution, to 
>this extent anyway, within a line.
>Peter S. Shenkin	 Columbia Univ. Biology Dept., NY, NY  10027

In C, you can put more than one statement on a line!  So it would be
feasible, if awkward, to do something like

	float a,b,c,d,e,t;

	t=a+b;t+=c;d*=t;d/=e;

for the FORTRAN

	D=(D*((A+B)+C))/E

Obviously it's possible but unnecessary to use four different lines:

	t=a+b;
	t+=c;
	d*=t;
	d/=e;
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
	   go for it!  			allegra,ulysses,vax135}!ttrdc!levy



More information about the Comp.lang.c mailing list