Most will know that C++ mangles external names in a compiler specific way such that they encode the types of function parameters and the nesting of class
es and namespace
s. People are probably less aware that most C compilers also mangle some names to make them unique inside compilation units.
Month: June 2011
non-deterministic programs through unspecified behavior
C defines different types of behavior for certain features:
- deterministic behavior, most features such as the
!
operator - unspecified behavior, where the compiler has a choice on how to implement a feature, e.g the evaluation order of subexpressions. Here, I also include “needs not to” behavior, where it seems that it has been forgotten to mention this explicitly, e.g if two
const
qualified compound literals of the same scope with the same value are folded into one object - implementation defined behavior, behavior unspecified by the standard but for which an implementation has to document its choices, e.g the greatest value of an
int
. - undefined behavior, the compiler is allowed to eat your hard disk for breakfast, such as when accessing an array element out of bounds
Towards its end, the C standard has long list for the later three types.
Where most C programmers will know about the possible pitfalls of undefined behavior, it seems that unspecified behavior has a lot less attention although it might have severe consequences, too.
Continue reading “non-deterministic programs through unspecified behavior”