Kenneth said:
Roberto said:
(e-mail address removed) wrote: [...]
Still feel a little
puzzled, please someone could explain this.
They all invoke undefined behavior, so anything can happen.
Contrary to popular believe in comp.lang.c, this does not mean that
demons may fly out of your nose but that the compiler is not required
to interpret these statements in any one well defined way, or to do
anything that is consistent and repeatable, or to do anything that
looks "reasonable" to you.
[...]
And causing demons to fly out your nose is a perfectly valid way to
"interpret these statements", as far as the standard is concerned.
While it is highly unlikely that a compiler writer will go out of
his way to cause such behavior,
You didn't spend much time around compiler writers, did you?
there is nothing stopping one from
creating such behavior, and such behavior would still be conforming
to the standard.
The odds are that behaviour of code with things like "j++ + j" will
be one of two scenarios (returning either "j+j" or "j+j+1", with j
being incremented by one in both cases), but that is only because
the compiler writer simply allowed the undefined behavior to be
ignored, and treated the "j++" as if it were any other instance of
"j++" in a valid statement.
However, "the odds are" is not the same as "the standard requires",
and "undefined behavior" is exactly that -- undefined. The standard
places absolutely no restrictions on the outcome, and does not
prohibit the creation of nasal demons.
I understand that perfectly well. I am aware that asking a compiler to
process something like "i = i++ + ++i;" could cause any, or all, or
any combination of the following to happen, without violating the C
standard:
a) The customary appearance of nasal demons.
b) Peace on Earth to all men of goodwill.
c) The discovery that ether and phlogiston are responsible, after all,
for the propagation of electromagnetic waves and heat, respectively.
d) The reversal of the movement of the planet's tectonic plates,
putting South America and Africa in a collision course. (You have been
warned, visit Buenos Aires while you can.)
e) The discovery of weapons of mass destruction in Iraq.
f) The selective reversal of the magnetic field on the platters in my
hard disk, in such a way that my Ubuntu Linux box will be downgraded
to a legitimate copy of Windows Vista, Service Pack 72.
Still, while presenting things this way may elicit a chuckle from
comp.lang.c veterans, it is not the right pedagogical approach to be
used when answering questions from beginners.
I believe the way my answer was worded was both correct and more
helpful to the OP.
Let's bring up the nasal demons later, when he is mature enough and
strong enough to face the truth.
Amicably yours,
Roberto Waltman.