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:
“There are those who scoff at the schoolboy, calling him frivolous and shallow. Yet it was the schoolboy who said Faith is believing what you know aint so.”
—Mark Twain [Samuel Langhorne Clemens] (18351910)
“The metaphor of the king as the shepherd of his people goes back to ancient Egypt. Perhaps the use of this particular convention is due to the fact that, being stupid, affectionate, gregarious, and easily stampeded, the societies formed by sheep are most like human ones.”
—Northrop Frye (b. 1912)