3 ms·
Not sure which way you mean it, but it's important to note that this is only true if you have C-like undefined behavior in your language, and is not true of com
by mikeash 14y ago
Not sure which way you mean it, but it's important to note that this is only true if you have C-like undefined behavior in your language, and is not true of computer languages in general. It's not all that hard to define the results of all operations. I believe a lot of languages (e.g. Java) do this. For example:
- C makes it undefined to access beyond the end of an array. It's possible to define this as always throwing an exception or terminating the program.
- C makes it undefined to overflow a signed integer type. We can define this as following two's complement rules, or terminating the program.
- Writing to a constant string is undefined. We can define this to always work, to always terminate the program, or we can even define a type system that makes it impossible to even try.
Once you define all behavior like this, then there is no undefined behavior. A valid program is one that your compiler accepts, no more and no less. The program can still have bugs, of course, but if the program compiles, its output is always well-defined.
- mansr 14y agoThis entire thread is specifically about C.