__cdecl

The __cdecl convention is the convention used by the compiler. The following list shows the implementation of this calling convention:

Element Implementation

Argument-passing order Right to left
Argument-passing convention By value, unless a pointer or reference type is passed
Stack-maintenance responsibility Calling function adjusts the stack
Name-decoration convention Underscore character (_) is prefixed to names
Case-translation convention No case translation performed

To declare a function as __cdecl, use a declaration of the form:

char * __cdecl stricmp( char *szString1,

char *szString2 );

Note that, in the preceding declaration, the modifier __cdecl modifies the name immediately to its right, stricmp.

The following list shows how values are returned from functions specified as __cdecl:

Type Return Location

char, unsigned char Returned in AL register.
int, unsigned, short, unsigned short, “pointer to near Returned in AX register.
long, unsigned long Returned in DX:AX registers.
float, double Copied to the global variable __fac; returns a pointer to __fac in AX or DX:AX, depending on addressing model.
long double Placed on the NDP (numeric data processor) stack using the FLD instruction.
Structures Depends on the size of the structure:
  1 byte: returned in AL register 2 bytes: returned in AX register 4 bytes: returned in DX:AX registers
  For structures larger than 4 bytes, the caller passes a pointer to a hidden variable that will receive the return value as the last item pushed. The structure being returned is copied into the location pointed to by the hidden variable. The pointer to the hidden variable is then returned in AX or DX:AX (for near or far addressing models, respectively).

In 16-bit compilations, the variable-argument facility of ANSI C can be used only with functions of type __cdecl. In 32-bit compilations, variable-argument lists can also be used with the __stdcall calling convention, discussed on topic .