### _System Calling Convention in Windows

The language details of this calling convention are the same as for all other calling conventions. _System has the additional restriction that an unprototyped _System function with a variable number of arguments will not work.

To use this linkage convention, use the _System keyword in the declaration of the function. You can make _System the default linkage by specifying the /Ms compiler option.

The following rules apply to the _System calling convention:

- All parameters are passed on the stack.
- The parameters are pushed onto the stack in a lexical right-to-left order.
- The called 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 the return values is passed as a hidden parameter in EAX.
  4 bytes
    EAX
  3 bytes
    EAX The address to place the 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 parameter, and the addresss is passed back in EAX.

- Function names are decorated with an underscore prefix, and a suffix which consists of an at (@), followed by the number of bytes of parameters (in decimal). Parameters of less than four bytes are rounded up to four bytes. Structure sizes are also rounded up to a multiple of four bytes. For example, a function fred prototyped as follows:

        int fred(int, int, short);

  would appear as:

        _fred@12

  in the object module.

> Note: 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.

- Prototyped variable argument functions with _System linkage are silently converted by the compiler to __cdecl linkage.

Calling Conventions

_System Calling Convention in OS/2