P
Phlip
DaKoadMunky said:This might be a question for another posting or group, but here goes...
int n = 0;
n = n++; //Undefined due to multiple modifications between SP
If this is undefined why even allow it to compile?
Compilers are not required to specify what happens to undefined behavior.
When the behavior is easy to detect, the compiler might bounce it, or warn
about it.
When the behavior is hard to detect, a compiler
And a compiler might just produce opcodes without bothering to warn
anything, even if it's easy to detect.
Consider:
SimCity & aCity = *(SimCity *) NULL;
Null references are undefined. The indefinity occurs at the left star *.
However, if a compiler added a check for this situation, it would commit to
checking where the right argument is less obvious. Checking at runtime would
slow down millions of innocent and correct dereferences. So the compiler
compiles the well-formed code, and lets the programmer live with the
consequences of their actions.
What is the value in allowing this to be syntatically correct yet saying
anything at all could happen?
As a false convenience for naive programmers.
But what if n and m were references to the same integer. A compiler might
not easily be able to check that. If it can't check all forms of a
situation, it won't check any, including the obvious ones.