/Gd, /Gr, /Gz (Calling Convention)
These options determine the order in which function arguments are pushed onto the stack; whether the caller function or called function removes the arguments from the stack at the end of the call; and the name-decorating convention that the compiler uses to identify individual functions.
/Gd
/Gr
/Gz
Remarks
Note
These compiler options are only available in the compiler targeting x86; these compiler options are not available in the compilers targeting x64 or Itanium.
/Gd, the default setting, specifies the __cdecl calling convention for all functions except C++ member functions and functions marked __stdcall or __fastcall.
/Gr specifies the __fastcall calling convention for all functions except C++ member sfunctions and functions marked __cdecl or __stdcall. All __fastcall functions must have prototypes.
/Gz specifies the __stdcall calling convention for all functions except C++ member functions and functions marked __cdecl or __fastcall. All __stdcall functions must have prototypes.
Functions that take a variable number of arguments must be marked __cdecl.
/Gd, /Gr, and /Gz are not compatible with /clr:safe or /clr:pure.
Note
For x86 processors, by default, C++ member functions use __thiscall.
For all processors, a member function that is explicitly marked as __cdecl, __fastcall, or __stdcall uses the specified calling convention. A member function that takes a variable number of arguments always uses the __cdecl calling convention.
__cdecl Specifics
For C, the __cdecl naming convention uses the function name preceded by an underscore ( _ ); no case translation is performed. Unless declared as extern "C", C++ functions use a different name-decorating scheme. For more information, see Decorated Names.
__fastcall Specifics
Some of a __fastcall function's arguments are passed in registers (for x86 processors, ECX and EDX), and the rest are pushed onto the stack from right to left. The called routine pops these arguments from the stack before it returns. Typically, /Gr decreases execution time.
Note
Be careful when using the __fastcall calling convention for any function written in inline assembly language. Your use of registers could conflict with the compiler's use.
For C, the __fastcall naming convention uses the function name preceded by an at sign (@) followed by the size of the function's arguments in bytes. No case translation is done. The compiler uses the following template for the naming convention:
@function_name@number
When using the __fastcall naming convention, use the standard include files. Otherwise you will get unresolved external references.
__stdcall Specifics
A __stdcall function's arguments are pushed onto the stack from right to left, and the called function pops these arguments from the stack before it returns.
For C, the __stdcall naming convention uses the function name preceded by an underscore ( _ ) and followed by an at sign (@) and the size of the function's arguments in bytes. No case translation is performed. The compiler uses the following template for the naming convention:
_functionname@number
x86 Specific
This option has no effect on the name decoration of C++ methods and functions. Unless declared as extern "C", C++ methods and functions use a different name-decorating scheme. For more information, see Decorated Names.
For more information about calling conventions, see Calling Conventions.
END x86 Specific
To set this compiler option in the Visual Studio development environment
Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.
Click the C/C++ folder.
Click the Advanced property page.
Modify the Calling Convention property.
To set this compiler option programmatically
- See CallingConvention.