11.1 Types of functions and macros

-----------------------------------

C-- now supports 4 ways of calling a function: cdecl, pascal, stdcall

and fastcall. The features of these are summarized below.

cdecl This type of function call is the default for C. The function

----- parameters are transferred in inverse order to how they are found in

the source text. The stack is cleared of the parameters after completing

the function. This is a very suitable method for functions with a variable

number of parameters.

pascal In this type of call, parameters are transferred in the same order

------ in which they were recorded. The stack is cleared of the parameters

by the function itself. This method is more compact than cdecl but can only

be used with a constant number of parameters.

stdcall This is a cross between the first two types. The parameters are

------- transferred in the inverse order to how they are found in the

stack, and the stack is cleared of the parameters by the function.

fastcall In this type of function call, parameters are transferred via

-------- registers, so there is no need to clear the stack of parameters.

There are limits on the number of parameters which can be transferred. This

limit is three for C, but six for C--. In C-- parameters are by default

transferred in teh order: 1 - AX/EAX, 2 - BX/EBX, 3 - CX/ECX, 4- DX/EDC, 5

- DI/EDI, 6 - SI/ESI. Only four parameters of types char or byte can be

transferred, and only to the first four registers: 1 - AL, 2 - BL, 3 - CL,

4 - DL. The order of registers can be changed if it is clearly indicated

either while declaring functions or when defining them. Fastcall functions

are also sometimes called register functions.

By default, in C-- if a function name is written upper-case, it is

considered to be a fastcall function. If, however, there is at least one

lower-case letter in the name, it is of call type pascal, except for

programs compilable with the keys /w32, /w32c, or /DLL, for which the

default is stdcall. The default can be changed to any other type, by

declaring this function with the type of call wanted.

Functions are declared to instruct the compiler on how to return from a

function, how to transfer parameters to a function, and the number of

functions.