6.3 Calling mechanism

By default, the calling mechanism the compiler uses is register, that is, the compiler will try to pass as much parameters as posible by storing them in a free register. Not all registers are used, some registers have a special meaning, but this depends on the CPU.

Function results are returned in the accumulator (rst register), if they t in the register. Methods calls (from either objects or clases) have an additional invisible parameter which is self. This parameter is the leftmost parameter within a method call (it is therefore the last parameter passed to the method).

When the procedure or function exits, it clears the stack.

Other calling methods are available for linking with external object les and libraries, these are summarized in table (6.3). The rst column lists the modier you specify for a procedure declaration. The second one lists the order the paramaters are pushed on the stack. The third column species who is responsible for cleaning the stack: the caller or the called function. The alignment column indicates the alignment of the parameters sent to the stack area. Finally, the fth column indicates if any registers are saved in the entry code of the subroutine.


Table 6.3: Calling mechanisms in Free Pascal






Modier Pushing orderStack cleaned byalignment registers saved





Left-to-right Function default None
register Left-to-right Function default None





cdecl Right-to-left Caller GCC alignmentGCC registers
interruptRight-to-left Function default all registers
pascal Left-to-right Function default None
safecall Right-to-left Function default GCC registers
stdcall Right-to-left Function GCC alignmentGCC registers
oldfpcall Right-to-left Caller default None

More about this can be found in chapter 7, page 352 on linking. Information on GCC registers saved, GCC stack alignment and general stack alignment on an operating system basis can be found in Appendix I. As of version 2.0 (actually, in 1.9.x somewhere) , the register modier is the default calling convention, prior to that, it was the oldfpcall convention.

The default calling convention, i.e., the calling convention used when none is specied explicitly, can be set using the f$calling g directive, section 1.1.5, page 36

Remark: The popstack modier is no longer supported as of version 2.0, but has been renamed to oldfpcall. The saveregisters modier can no longer be used.