Jens Gustedt's Blog

June 24, 2011

Name mangling in C

Filed under: C99 — Jens Gustedt @ 19:01

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 classes and namespaces. People are probably less aware that most C compilers also mangle some names to make them unique inside compilation units.


June 19, 2011

non-deterministic programs through unspecified behavior

Filed under: C99, language — Jens Gustedt @ 14:07

C defines different types of behavior for certain features:

  1. deterministic behavior, most features such as the ! operator
  2. 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
  3. 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.
  4. 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.

Create a free website or blog at