R
Richard
Actually, every time I post this sort of thing (which is my stock sort
of response to idiotic "Why this works?" type posts), I forget about the
need for a "return 0;" at the end (actually testing my code with gcc
with all warnings turned on would have shown this up).
Still, I have to ask this: The C standard of course says that once UB
happens, all bets are off. And, let's assume for the sake of argument
that the above program does cause UB. But the point is, it doesn't
cause the UB until the function returns. I.e., the statement above is
"... once UB happens". But it is not the case that future UB can cause
current operations to fail. So, the above program would (under all the
usual CLC rules) work, as far as printing "hello, world", even though it
might start global thermonuclear war thereafter.
Doesn't UB make Heathfield's toaster play the star spangled banner and
then insult Muslims? Oh. I see the link.