Developer Guide and Reference

Contents

C/C++ Calling Conventions

There are a number of calling conventions that set the rules on how arguments are passed to a function and how the values are returned from the function.

Calling Conventions on Windows*

The following table summarizes the supported calling conventions on Windows*:
Calling Convention
Compiler Option
Description
__cdecl
/Gd
This is the default calling convention for C/C++ programs. It can be specified on a function with variable arguments.
__stdcall
/Gz
Standard calling convention used for Win32 API functions.
__fastcall
/Gr
Fast calling convention that specifies that arguments are passed in registers rather than on the stack.
__regcall
/Qregcall
specifies that
__regcall
is the default calling convention for functions in the compilation, unless another calling convention is specified on a declaration.
Intel® C++ Compiler calling convention that specifies that as many arguments as possible are passed in registers; likewise,
__regcall
uses registers whenever possible to return values. This calling convention is ignored if specified on a function with variable arguments.
For more information about the Intel-compatible vector functions ABI, see the article
Vector (SIMD) Function ABI
at https://software.intel.com/en-us/articles/vector-simd-function-abi.
For more information about the GCC vector functions ABI, see the item Libmvec - vector math library document in the GLIBC wiki at sourceware.org.
__thiscall
none
Default calling convention used by C++ member functions that do not use variable arguments.
__vectorcall
/Gv
Calling convention that specifies that a function passing vector type arguments should utilize vector registers.

Calling Conventions on Linux*
and
macOS*

The following table summarizes the supported calling conventions on Linux*
and
macOS*
:
Calling Convention
Compiler Option
Description
__attribute((cdecl))
none
Default calling convention for C/C++ programs. Can be specified on a function with variable arguments.
__attribute((stdcall))
none
Calling convention that specifies the arguments are passed on the stack. Cannot be specified on a function with variable arguments.
__attribute((regparm (number)))
none
On systems based on IA-32 architecture, the regparm attribute causes the compiler to pass up to
number
arguments in registers
EAX
,
EDX
, and
ECX
instead of on the stack. Functions that take a variable number of arguments will continue to pass all of their arguments on the stack.
__attribute__((regcall))
-regcall
specifies that
__regcall
is the default calling convention for functions in the compilation, unless another calling convention is specified on a declaration.
Intel® C++ Compiler calling convention that specifies that as many arguments as possible are passed in registers; likewise,
__regcall
uses registers whenever possible to return values. This calling convention is ignored if specified on a function with variable arguments.
__attribute__((vectorcall))
none
Calling convention that specifies that a function passing vector type arguments should utilize vector registers.

The __regcall Calling Convention

The
__regcall
calling convention is unique to the Intel® C++ Compiler and requires some additional explanation.
To use
__regcall
, place the keyword before a function declaration. For example:
Example
__regcall int foo (int i, int j);
// Linux*
and
macOS*
__attribute__((regcall)) foo (int I, int j);

Available __regcall Registers

All registers in a
__regcall
function can be used for parameter passing/returning a value, except those that are reserved by the compiler. The following table lists the registers that are available in each register class depending on the default ABI for the compilation. The registers are used in the order shown in the table.
Register Class/Architecture
IA-32 for Linux*
IA-32 for Windows*
Intel® 64 for Linux*
Intel® 64 for Windows*
GPR
EAX, ECX, EDX, EDI, ESI
ECX, EDX, EDI, ESI
RAX, RCX, RDX, RDI, RSI, R8, R9, R10, R11, R12, R14, R15
RAX, RCX, RDX, RDI, RSI, R8, R9, R11, R12, R14, R15
FP
ST0
ST0
ST0
ST0
MMX
None
None
None
None
XMM
XMM0 - XMM7
XMM0 - XMM7