[comp.lang.c] evaluation order, unary +, etc.

blarson@castor.usc.edu.UUCP (04/12/87)

When I use parentheies in an expression, I do so for readability of
code and/or override operator presidence, NOT to force the calculation
to be done in that order.  Changing the meaning of parenthesies in C
would force me as a programer to write less readable code so the
optimizer could do it's job.

I do think having a way to force evalution order is not a bad idea, and
I'm not especially in love with the use of unary plus for it.  A cast
to volitile would be much better, it's saying what you mean.

	double a,b,c,d;
	
	a = (volitile double)(b + c) + d;

would mean calculate b+c before adding d.

If I was serious about proposing changes to C, I would probably
propose that the whole float/double portion be made optional.  I rarly
find them of any use, and can't justify having compiler/library
writers waste time on them.  (I am a full time programer, and can't
remember the last time I needed to to something in floating point.)
(OK, I admit this paragraph was added to show that not everyone uses C
for the same thing.  I think forcing parathasies to mean something
different than they currently do is just as bad for me as eliminating
floating point would be for you.)
-- 
Bob Larson
Arpa: Blarson@Usc-Eclb.Arpa
Uucp: (several backbone sites)!sdcrdcf!usc-oberon!castor.usc.edu!blarson
			seismo!cit-vax!usc-oberon!castor.usc.edu!blarson

john@viper.UUCP (04/13/87)

In article <1557@castor.usc.edu> blarson@castor.usc.edu.UUCP (Bob Larson) writes:
 >When I use parentheies in an expression, I do so for readability of
 >code and/or override operator presidence, NOT to force the calculation
 >to be done in that order.  Changing the meaning of parenthesies in C
 >would force me as a programer to write less readable code so the
 >optimizer could do it's job.
 >
Not necessarily!  The idea that several people seem to have come up with
at the same time is to use a compile switch on an entire file, or a #pragma
define to turn optimization on/off when desired.  You would not have to
change your code one iota (however much that is..) to -allow- optimization.
When a programmer wants to have his/her code optimized, the optimization
should be explicit, not implicit...  Since the exact nature of optimization
differs from compiler to compiler, this would allow portable code to be
written as a default case rather than requiring extra effort to figure out
which order was used and then having to use unary plus all over the place to
enforce that on every potentialy optimized statement in your program...
(If this doesn't seem like a nusance, this discussion is hopeless...)

 >I do think having a way to force evalution order is not a bad idea, and
 >I'm not especially in love with the use of unary plus for it.  A cast
 >to volitile would be much better, it's saying what you mean.
 >
 >	double a,b,c,d;
 >	
 >	a = (volitile double)(b + c) + d;
 >
 >would mean calculate b+c before adding d.

  Sorry, I'd rather use unary plus than this...  It's not a -bad- idea,
but you're effectively doing a unary-plus without the simplicity.  It
also assumes that optimization is default which is the primary point
I'm trying to get people to think about...

--- 
John Stanley (john@viper.UUCP)
Software Consultant - DynaSoft Systems
UUCP: ...{amdahl,ihnp4,rutgers}!{meccts,dayton}!viper!john