Undefined behavior

From Esolang
Jump to: navigation, search

Undefined behavior is the result of any action in a programming language that the language specification specifically avoids defining, without making any suggestions as to what might happen. An example in an esoteric programming language would be a program going off the right side or bottom of code space in 2L. Non-esoteric examples in C include using an uninitialized variable, overflowing an integer, and abusing sequence points - for example:

int b = 1;
b = b++; // undefined
int c = b++ * b--; // undefined

Code that exhibits undefined behavior may produce unexpected and inconsistent results, crash the program (or the interpreter), cause an error, etc. An implementation has no responsibility to try to do anything that even remotely makes sense when faced with undefined behavior, and in fact is perfectly free to make demons fly out of your nose if it wants to.