[comp.lang.c] sequence points

Purtill@MIT-MULTICS.arpa (04/12/87)

It would really help if some of the people complaining about the
standard would get a copy.  Some people seem to have the idea that the
standard allows the compiler to do anything it wants in the way of
rearranging expressions, eliminating temps, and so on.  This is not
true, there are things called sequence points which limit the compiler's
optimizations.  I won't go into details as my copy of the standard
(excuse me, draft proposed standard) is (1) somewhat old (from when they
were free) and (2) elsewhere.  But do look at the standard before
complaining bitterly.  (Note that limiting the optimization is not
necessarily a loser; the implementation is free to provide a flag to do
additional (nonANSI) optimizations, but when that flag is used, it
wouldn't be an ANSI compiler.  (The Convex compiler has a flag to do
"potentially unsafe" optimizations, for instance.))

^.-.^ Mark Purtill
((")) Purtill -at Multics.MIT.edu

pardo@june.cs.washington.edu (David Keppel) (01/23/88)

----

John Nelson sent me part of the ANSI draft standard having to do with
program execution.  Basically, under the new standard things such as

	foo = bar, baz = bum;

can be rearranged arbitrarily by the compiler as long as they obey
sequence-point rules.

The draft also mentions that the logical-AND and logical-Or operators
impose sequencing points.  This leads me to the following proposal:


	if ( bool1 && bool2 ) { ... }

means exactly what it has always meant.

	if ( bool1 &&& bool2 ) { ... }

means that the compiler can evaluate either or both arguments and
in any order, whatever is the fastest.  For more complex expressions,
the compiler is allowed to use DeMorgan's theorem and any other apriori
information it has at hand to speed the computation of the boolean.

If part of the expression is written using the short-circuit form of
the operators, then that part of the expression _must_ be evaluated
in short-circuit form, but the rest of the expression can be reordered:

	if ( cp && ((*cp != 'a')|||(*cp != 'c')|||(!*cp)) ) { ... }

The "obvious" candidates are "&&&" and "|||".  I wonder if
(a) there are any others
(b) if this is at all a good idea

Please respond by e-mail, I'll summarize.

	;-D on  (Well it _seemed_ like a good idea!)  Pardo