Heathfield puts his foot in doo doo because I would never, in the
absence of further information, say that the above statement belongs
to the class of "C statements that are known not to have side effects"
because I don't see the code of foo. If the code of foo is unavailable
to an optimizer doing this taxonomy, it would put the statement in the
unknown class.
Heathfield is mobilizing his own limitations and that of his followers
here in what Adorno calls the "negative dialectic". This is where the
pulse of history reverses sign and instead of sharing knowledge and
using knowledge, people spread ignorance through a misnamed
"skepticism" and a false asceticism of belief.
I think he may be right, at least on this specific example. You will
note that he does not refer to an expression which *does* have side
effects, only one which *may* have side effects. I'd say the above is
in the latter category, as it contains a function call, and function
calls *may* have side effects.
Examples:
int x = 3 + 4; /* known not to have side effects */
int z = x++; /* may have side effects */
Note that we are not distinguishing between "may have side effects" and
"necessarily has side effects". We can't, because function calls are
ambiguous in that regard. But if an expression has no function calls in it,
you can tell whether or not it has side effects in most cases. You can
always tell whether it may, except that in some cases the probability is zero:
int a = (x <= z) ? (++x) : (0);
I would say that strictly speaking, we know that this expression does not
have side effects, because (assuming no intervening code), we know that x is
8 and z is 7, so we necessarily don't evaluate the ++x. However, I think
this analysis proves his point incorrect. You can correctly determine that
this expression CANNOT have a side effect, but you can't do it by looking
only at the syntax.
On Seebach's left shoulder we see a better angel of his nature: on his
right, a worse. We see him figuring out compiler optimization on his
very own, having majored in something other than compsci in skewl
(perhaps to his credit math).
But I'm afraid you don't even know, Peter, what means "syntax". If the
above statement is preceded by assignments to x and 7 of constants,
flow analysis syntactically proves that the second statement inherits
the property of being without side effects. If you define "flow
analysis" as "not syntax", that's the logical fallacy of definition
against disproof. And if you start shit with me over the meaning of
"syntax", I swear to God I'll finish it.
I do not have a lot of experience in C compilers, but it now appears
to me you have less.
On the other hand, it may be that for his purposes, this counts as "may have
side effects", even though the probability of the side effect occurring is
zero. You can certainly identify a category of expressions that absolutely
do not have side effects, by syntax alone -- there are some expressions where
analyzing the syntax of the expression proves that there can never be side
effects. (Actually, I'm not sure of this, either. Does access to a volatile
count as a "side effect"? If so, I don't think that counts as a syntactic
feature anymore. Syntactically, volatile's just a qualifier, it doesn't
have any unique syntactic role...)
You really should have taken those classes. All this stuff is in Aho/
Sethi/Ullman. It is doable for some C and it's what optimizers do.
This is why you erred if as a voting member of the C99 standards
effort, you issued an across the board declaration that the "mere" C
programmer could not have the right to expect certain orders of
evaluation in non-optimized code in order to protect the profits of
your corporate sponsors.