### __cdecl Calling Convention

The __cdecl linkage is very similar to the OS/2 __System linkage convention. All general purpose registers are preserved except for EAX, ECX, and EDX. Note that, unlike the OS/2 _System linkage, the number of dwords used to store parameters is not passed in AL.

To use this linkage convention, use the __cdecl keyword in the declaration of the function. You can make __cdecl the default linkage by setting the /Mc compiler option.

The following rules apply to the __cdecl calling convention:

- All parameters are passed on the stack.
- The parameters are pushed onto the stack in a lexical right-to-left order.
- The calling function removes the parameters from the stack.
- Floating point values are returned in ST(0). All functions returning non-floating point values return them in EAX, except for the special case of returning aggregates less than or equal to four bytes in size. For functions that return aggregates less than or equal to four bytes in size, the values are returned as follows:
  Size of Aggregate
    Value Returned in
  8 bytes
    EAX-EDX pair
  5, 6, 7 bytes
    EAX The address to place return values is passed as a hidden parameter to EAX.
  4 bytes
    EAX
  3 bytes
    EAX The address to place return values is passed as a hidden parameter to EAX.
  2 bytes
    AX
  1 byte
    AL

  For functions that return aggregates greater than four bytes in size, the address to place the return values is passed as a hidden paramter, and the addresss is passed back in EAX.

- Function names are decorated with an underscore prefix when they appear in object modules. For example, a function named fred in the source program will appear as _fred in the object.

When building export or import lists in module definition files, the decorated version of the name should be used. This is automatically handled when using #pragma export and #pragma import.

When building export or import lists in module definition files, the decorated version of the name should be used. This is automatically handled when using #pragma export and #pragma import. If you use undecorated names in the module definition file, you must give the object files to the ILIB utility along with the module definition file. ILIB will use the object files to determine how each name ended up after decoration.

Calling Conventions

Examples Using the __cdecl Calling Convention
ILIB Objects