Main Page | See live article | Alphabetical index

Name decoration

In computer programming, name decoration is a way to encode additional information about the name of a function, structure, class or another datatype to pass more semantic information from the compilers to linkers.

Any object code produced by compilers is usually linked with other object codes, produced by the same or another compiler, by a type of program called a linker. The linker needs a great deal of information on each program entity. For example, to correctly link a function it needs its name, the number of arguments, their type, and so on. To do so, the name is decorated with additional control characters. For example, a C function called "MatrixMult" becomes:


to indicate that the function arguments need 8 bytes of storage on the stack and, if the size of each argument is fixed for example to 4 bytes (32 bit), that there are 2 arguments. Other common actions are to add some prefixes, usually with an abundance of underlines (like __func__), or some standard capitalization.

Many programming languages like C, Fortran and Pascal define standards for name decoration. Using these standards, object code produced by a compiler can be linked to object code produced by another compiler.

The C++ language does not define a standard decoration scheme. So each compiler uses its own. Combined with the fact that C++ decoration can be fairly complex (storing information about classes, default arguments, variable ownership, operator overloading, etc), it means that object code produced by different compilers is not usually linkable.

A less forgiving (and more honest) term for this technique is name mangling.