Where does the standard say that the side effect of incrementing a must
not occur until the sequence point? (Hint: It doesn't.)
The expression in question is the entire function call.
By themselves, the subexpressions ++a and a + 5 are well defined.
But because they appear together as part of a larger expression
with no intervening sequence points, the behavior is undefined.
Once again, 6.5p2:
Between the previous and next sequence point an object shall
have its stored value modified at most once by the evaluation
of an expression. Furthermore, the prior value shall be read
only to determine the value to be stored.
The printf violates the second sentence; the second subexpression a +
5 reads the value of a, but not to determine the value to be stored.
That second sentence can be confusing (it confused me for a long
time). The point is that if an object is read just to determine
the value to store in that same object, there's no problem, since
the read logically has to occur before the write. But if the object
is read in a part of the expression that doesn't contribute to the
computation of the value to be stored, then the read and the write
could occur in either order, at the whim of the compiler.
The authors of the standard *could* have placed some limitations
on how such expressions are evaluated, saying, for example, that
either ++a must be evaluted (including its side effect) before a +
5, or vice versa. But that would constrain the optimizations that
This is completely false.
Compiler optimization is not done to source code. It is done to an
intermediate representation whilst preserving the abstract semantics
of the language at all times. Real compiler optimization NEVER results
in different results for different optimizing compilers that are
correct.
However, neither K&R nor the authors of the standard had the courage
or industry to fully specify the semantics of C. Although they covered
their incompetence up with talk of a strange sort of American
"freedom" (to work 24/7 in front of a computer), their objective
reason was to preserve the investment of Wall Street capitalists who
refused to change compilers without what the MBA boys call a "business
case" (where "a business case" means "how does your plan make me
richer").
This appeal to the needs of "optimization" is familiar to me. It
occurs when little techies refuse to face the objective fact that they
are not the independent "scientists" that they fancy themselves to be,
and know that if they suggest something which costs money without
making it, the big boys will unman them.
compilers are able to perform and make the standard more complex.
"Too complex", also, means "don't make me think".
"Far from perceiving such prohibitions on thought as something
hostile, the candidates ['for posts'] – and all scientists are
candidates – feel relieved. Because thinking burdens them with a
subjective responsibility, which their objective position in the
production-process prevents them from fulfilling, they renounce it,
shake a bit and run over to the other side."
Adorno accurately perceived as a white collar worker in the Depression
in the US that all "jobs" then as now were so conditional, so
temporary-even-when-permanent, that to be a white collar "scientist"
was to be at all times a candidate, for a new and better post that
could be used for leverage at one's current job, and for one's own
job. They internalized unspoken and unwritten boundaries upon thought
and at these limits, would turn remarkably anti-intellectual and
perverse in a way that would bely their offline selves, listeners to
Beethoven discussing great events in their mortgaged living rooms.
We think of ourselves as "middle class". However, Adorno knew, since
he lived during the era in which it happened, that World War I had
destroyed the linkage of money with gold, so that any putative member
of the middle class could be impoverished by vast changes over which
he had no control. Today, we're dependent not on government largesse
(which would be bad enough) but on corporate largesse (which is
worse). Interestingly, Adorno reflects Ron Paul's views on this matter
alone, without Paul's foolish and racist libertarianism.
Computer technicians suffer from a lack of fit as seen here from their
self-image as "independent professionals" and corporate slaveys
without a bank account that's independent of free-floating exchange
rates, so when confronted with the realities of this lack of fit, they
turn to savagery, such as is happening here to someone who, rightly,
questions the wisdom of calling something "undefined" when for any
given compiler, it isn't.
Developing a compiler is as much a scientific venture as it is
industrial, but as soon as the welfare state, with its expenditure
unlinked to the flourishing of the wealthy, appeared in America and
Britain, the privately owned media named this to be "waste".
The lower middle class, internalizing this Puritanism, was ready in
computing to differentiate sharply between direct labour such as
writing an application program, and indirect labour such as writing an
insanely great tool that would automatically generate hundreds of
actual programs. Capitalism (cf Max Weber) having become a new
religion, a priesthood of CEOs was jealous of government making its
fundamental gesture, that of spending money to make money, and
government successes such as the Tennessee Valley Authority and rural
electrification horrified this priesthood.
Therefore, both K&R and the standards writers knew instinctively that
to actually define the semantics of C would be to tell private firms
to do something with no clear reward, and this would be decried in the
same terms as were government programs in the arts: "elitist",
"telling people what to do", "airy-fairy", "theoretical" and so on.
The result? A fucking mess, and constant assaults on people who
haven't got religion.