Subroutine Calling Protocol
(Redirected from Calling Convention)
Jump to navigation
Jump to search
A Subroutine Calling Protocol is a programming language implementation-level scheme that defines how subroutines or functions receive parameters from their caller and return a result.
- Context:
- It can (typically) involve the specification of where and how parameters are passed to a function and where and how results are returned, often via registers or within a stack frame on the call stack.
- It can (often) include design choices about dividing the tasks of preparing for a function call and restoring the environment after the function's completion between the caller and the callee.
- It can (typically) ensure that functions within a program adhere to a consistent method of transferring data and control, which is crucial for correct and reliable program execution.
- It can (often) vary between different programming languages, compilers, and operating systems.
- ...
- Example(s):
- The cdecl calling convention, commonly used in C and C++ on x86 architectures, where the caller cleans the stack.
- The stdcall calling convention]], often used in the Windows API, where the callee is responsible for cleaning the stack.
- A Python-based calling convention, such as:
- ...
- Counter-Example(s):
- Interpreter-based execution, where the program is executed directly by an interpreter without a predefined calling convention.
- High-level Language Virtual Machine implementations, such as the Java Virtual Machine (JVM) or the Python interpreter, where the calling convention is abstracted away from the programmer.
- Inline Assembly in high-level languages, which may bypass standard calling conventions for direct control over the hardware.
- Programming Language Closures In languages like JavaScript, calling conventions are less rigid due to different scoping and passing mechanisms for functions and their arguments.
- ...
- See: Call Stack, Computer Science, Programming Language Implementation, Subroutine, Parameter (Computer Programming), Return Statement, Stack Frame.
References
2024
- (Wikipedia, 2024) ⇒ https://en.wikipedia.org/wiki/calling_convention Retrieved:2024-1-25.
- In computer science, a calling convention is an implementation-level (low-level) scheme for how subroutines or functions receive parameters from their caller and how they return a result. When some code calls a function, design choices have been taken for where and how parameters are passed to that function, and where and how results are returned from that function, with these transfers typically done via certain registers or within a stack frame on the call stack. There are design choices for how the tasks of preparing for a function call and restoring the environment after the function has completed are divided between the caller and the callee. Some calling convention specifies the way every function should get called. The correct calling convention should be used for every function call, to allow the correct and reliable execution of the whole program using these functions.