Calling Convention

In computer science, a calling convention is a scheme for how subroutines receive parameters from their caller and how they return a result; calling conventions can differ in:

  • where parameters and return values are placed (in registers; on the call stack; a mix of both)
  • the order in which parameters are passed (or parts of a single parameter)
  • how the task of setting up for and cleaning up after a function call is divided between the caller and the callee
  • which registers that may be directly used by the callee may sometimes also be included (otherwise regarded as an ABI-detail).
  • which registers are considered to be volatile v. non-volatile and, if volatile, need not be restored by the callee

Different programming languages use different calling conventions, and so can different platforms (CPU architecture + operating system). This can sometimes cause problems when combining 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. Even a program using a single programming language may use multiple calling conventions, either chosen by the compiler, for code optimization, or specified by the programmer.

Architectures almost always have more than one possible calling convention. With many general-purpose registers and other features, the potential number of calling conventions is large, although some architectures are specified to use only one calling convention, supplied by the architect.

Famous quotes containing the words calling and/or convention:

    [T]he most artful method [of courtship] would be this, to tell her that what she doth not possess is useless and contemptible, that weakness and imperfection is the perfection of a woman, that I am stark mad in love with ignorance; and thus shall I allure her by calling her [a] fool.
    Sarah Fielding (1710–1768)

    No convention gets to be a convention at all except by grace of a lot of clever and powerful people first inventing it, and then imposing it on others. You can be pretty sure, if you are strictly conventional, that you are following genius—a long way off. And unless you are a genius yourself, that is a good thing to do.
    Katharine Fullerton Gerould (1879–1944)