Jack Klein said:
The code is broken because it does something that the C standard says
it undefined behavior, a very specific term. Whatever the program
actually does is irrelevant and off-topic here. The C language does
not know or care, and anything the program does is just as right or
just as wrong as anything else.
On the other hand, it can sometimes be useful to know what a
particular compiler is likely to do when confronted with undefined
behavior. Sometimes fixing the code isn't an option, or requires a
tremendous amount of effort; for example, if the code has already been
deployed, and is generally working correctly, the risk of making a
change may exceed the benefit of fixing a possible bug. There may be
other code that incorrectly depends on a the way a particular instance
of undefined behavior is handled; fixing one but not the other can
break a working program, even if it works only by accident.
Also, if I see "void main()", for example, I'm going to want to
correct it, but knowing that most compilers don't actually screw
things up too badly in the presence of "void main()" might tell me
that I need to keep looking elsewhere for the cause of the mysterious
bug I'm seeing.
For the purpose of writing new code, all you really need to know is
that undefined behavior is to be avoided. For the purpose of
understanding the behavior of existing code, knowing some of the
undefined and implementation-specific details can be useful -- as long
as you're aware that the details are undefined and
implementation-specific.
I don't believe that the original poster's situation was one that
calls for this kind of knowledge, though.