The C + + compiler's function name decoration rules

Source: Internet
Author: User
Tags drawtext

The name decoration of a function (decorated name) is a string that the compiler creates during compilation to indicate the definition or prototype of a function. The link program or other tool sometimes needs to specify the function's name decoration to locate the correct position of the function. In most cases the programmer does not need to know the function's name decoration, and the link program or other tool will automatically differentiate them. Of course, in some cases it is necessary to specify the name decoration of the function, for example, in a C + + program, in order for the link program or other tools to match the correct function name, you must specify the name decorations for the overloaded function and some special functions such as constructors and destructors. Another case where the name decoration of a function needs to be specified is a function called C or C + + in the assembler. If the function name, calling convention, return value type or function parameter has any changes, the original name decoration is no longer valid, you must specify a new name decoration. The functions of C and C + + programs use different name decorations internally, which are described in each of these two ways.


1. C compiler's function name decoration rules

For the __stdcall calling convention, the compiler and linker precede the output function name with an underscore prefix, followed by a "@" sign and the number of bytes of its arguments, such as [email protected]. The __cdecl calling convention only adds an underscore prefix to the name of the output function, such as _functionname. The __fastcall calling convention adds an "@" symbol to the output function name followed by an "@" symbol and the number of bytes of its argument, for example @[email protected]

2. The C + + compiler's function name decoration rules

C + + 's function name decoration rules are somewhat complex, but the information is more sufficient, through the analysis of decorated names can not only know how to call the function, return value type, number of parameters and even parameter types. Regardless of the __cdecl,__fastcall or __stdcall invocation, the function decoration takes a "?" Start, followed by the name of the function followed by the start of the parameter table and the parameter list by the parameter type code. For __stdcall mode, the start identifier of the parameter table is "@ @YG", the __cdecl method is "@ @YA", and the __fastcall method is "@ @YI". The spelling codes for the parameter table are as follows:
X--void
D--char
e--unsigned Char
F--short
H--int
i--unsigned int
J--long
k--unsigned Long (DWORD)
M--float
N--double
_n--bool
U--struct
....
Pointers are somewhat special, using PA to represent pointers, and PB for const type pointers. The following code indicates the pointer type, and if a pointer of the same type appears consecutively, substituting "0", a "0" represents a repetition. U represents the struct type, usually followed by the type name of the struct, and "@@" indicates the end of the struct type name. The return value of a function is not specially handled, and it is described in the same way as a function parameter, followed by the start flag of the parameter table, that is, the first item in the function parameter table is actually the return value type that represents the function. The parameter table identifies the end of the entire name as "@z" and ends with the "Z" identifier if the function has no arguments. Here are two examples, if you have the following function declaration:

int Function1 (char *var1,unsigned long);
Its function is decorated with the name "[email protected]@[email protected]" and for function declarations:
void Function2 ();
The function modifier name is "[email protected] @YGXXZ".

For C + + class member functions (which are called thiscall), the function's name decoration is slightly different from the non-member C + + function, starting with the insertion of the class name guided by the "@" character between the function name and the parameter table, followed by the start of the parameter table. The identity of the public member function is "@ @QAE", the identity of the protection (protected) member function is "@ @IAE", the identity of the private member function is "@ @AAE", and if the function declaration uses the Const keyword, the corresponding identity should be "@ @QBE", "@ @IBE" and "@ @ABE". If the parameter type is a reference to a class instance, use "AAV1" and "ABV1" for a reference to a const type. The following is a description of the name decoration rules for C + + member functions in class CTest:

classCTest {...Private:     voidFunction (int); protected:     voidCopyinfo (ConstCTest &src);  Public:     LongDrawText (HDC hdc,LongPosConsttchar* text, Rgbquad color, BYTE bUnder,BOOLBSet); LongInsightclass (DWORD dwclass)Const; ...... }; 

For member function functions, whose function is decorated with the name "[email protected]@@[email protected]", the string "@ @AAE" means that this is a private function. The member function Copyinfo has only one parameter, which is a const reference parameter to the class CTest, whose function is decorated with the name "[Email protected]@@[email protected]@z". DrawText is a more complex function declaration, with not only string parameters, but also struct parameters and hdc handle parameters, it is necessary to point out that HDC is actually a pointer to a hdc__ struct type, which is represented by "[Email protected]@", Its complete function modifier is called "[email protected]@@[email protected]@[email protected]@[email protected]". Insightclass is a common const function whose member function identifier is "@ @QBE", and the full decorated name is "[email protected]@@[email protected]".

Both the C function name decoration method and the C + + function name modification do not change the character case in the output function name, which differs from the Pascal calling convention in that the function name of the Pascal contract output is not decorated and capitalized.

3. View the function's name decoration

There are two ways to check the name decoration of a function in your program: Use the Compile output list or use the DUMPBIN tool. Use the/fac,/fas or/FACS command-line arguments to have the compiler output a list of functions or variable names. You can also get a list of functions or variable names in an obj file or lib file using the Dumpbin.exe/symbols command. In addition, you can use Undname.exe to convert a decorated name to an unmodified form.

The C + + compiler's function name decoration rules

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.