### 16-Bit Calling Conventions (OS/2)

Calling Conventions
There are three 16-bit calling conventions supported by IBM C and C++ Compilers: _Far16 _Cdecl,_Far16 _Fastcall, and _Far16 _Pascal.

The _Far16 _Cdecl and_Far16 _Pascal conventions are equivalent to the cdecl and pascal conventions used in other compilers. The_Far16 _Fastcall convention is equivalent to the Microsoft C Version 6.0 fastcall convention.

You can specify the calling convention for a function using keywords. For example, the following fragment uses keywords to declare the function dave as a 16-bit function using the _Far16 _Pascal calling convention:

       void _Far16 _Pascal dave(short, long);

General Rules for 16-bit Calling Conventions

- Types char, unsigned char, short, and unsigned short occupy a word on the stack.
- Types long and unsigned long occupy a doubleword with the value's high-order word pushed first.
- Types float, double, and long double are passed directly on the run-time stack as 32-, 64-, and 80-bit values respectively.
- char types are sign-extended when expanded to word or doubleword size; unsigned char types are zero-extended on the stack.
- Far pointers are 32 bits and are pushed such that the segment value is pushed first and the offset second.
- If the argument is a structure, the last word is pushed first and each successive word is pushed until the first word.
- All arrays are passed by reference.
- BP, SI, and DI registers must be preserved across the call.
- Segment registers must be preserved across the call.
- Structures passed on the stack are rounded up in size to the next word boundary.
- The direction flag must be clear on entry and exit.

Call Between 16-bit and 32-bit Code

Return Values from 16-Bit Calls
Differences Between the 16-bit Calling Conventions