Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!henry
From: henry@utzoo.UUCP (Henry Spencer)
Newsgroups: comp.lang.c
Subject: Re: conditional expression evaluation question
Message-ID: <7519@utzoo.UUCP>
Date: Tue, 13-Jan-87 16:23:55 EST
Article-I.D.: utzoo.7519
Posted: Tue Jan 13 16:23:55 1987
Date-Received: Tue, 13-Jan-87 16:23:55 EST
References: <207@rebel.UUCP>
Organization: U of Toronto Zoology
Lines: 22

>		if ((*cp++ | *cp++ | *cp++) == 0) ++triples;
> ...
> ...  My question is "Does C guarantee execution of portions of a
> conditional expression, even when the result is known after partial
> evaluation?"...

Basically, the answer is "no".  You get very few guarantees about the
order of execution or even presence of execution in C.  It is possible
that X3J11 mandates complete execution, and a good many compilers will
do it, simply because other sloppy people have made similar unwise
assumptions in the past and it causes too much trouble to violate them.
But I would suggest that it is extremely unwise to count on the above
code doing what you think it does.  (For another example, are you sure
that "*cp++" is atomic, i.e. that the postincrement will be done before
the next part of the expression?  I would think that an unwise assumption
too.)  There is too much chance of a "clever" compiler fouling things up.

Incidentally, not everyone would agree that the above is cleaner than
using "*(cp+1)" etc.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,decvax,pyramid}!utzoo!henry