Calling convention

From Wikipedia, the free encyclopedia

In computer science, a calling convention is a standardized method for a program to pass parameters to a function and receive a result value back from it. Calling conventions can differ in where they place parameters and return values (in registers; on the call stack; a mix of both), in the order in which parameters are passed, in name mangling, and in how responsibility for setting up and cleaning up a function call is distributed between the calling and the called code.

Different platforms use different calling conventions, and so can different programming languages, even on the same platform. In fact, multiple calling conventions can be used within the same program written using a single programming language (example: __stdcall, __cdecl and __fastcall calling conventions on Microsoft Windows). This can cause problems when writing software that combines modules written in multiple languages, or when calling operating system or library APIs from a language other than the one in which they are written; in these cases, special care must be taken to coordinate the calling conventions used by caller and callee.

Contents

[edit] Calling conventions on different platforms

[edit] x86

The x86 architecture features many different calling conventions. Due to the small number of architectural registers, the x86 calling conventions mostly pass arguments on the stack, while the return value is passed in a register. Some conventions use registers for the first few parameters to improve performance.

[edit] PowerPC

Since the PowerPC architecture has a large number of registers, most functions can be passed all arguments in registers; further arguments are passed on the stack, and space for register-based arguments is always allocated on the stack as a convenience to the called function, in case it needs to free up more registers. A single calling convention is used for all procedural languages.

[edit] MIPS

[edit] Sparc

[edit] See also

[edit] External links

In other languages