Calling Conventions in C/C
In C/C , different calling conventions are employed to determine how arguments are passed to functions and how results are returned. These conventions dictate the order and method of argument placement on the stack or in registers, as well as the responsibility for stack cleanup.
Available Calling Conventions
C/C offers multiple calling conventions, including:
-
cdecl: Arguments are pushed on the stack right-to-left, with specific registers designated for caller-saved and callee-saved data.
-
syscall: Similar to cdecl but does not preserve certain registers and requires passing the size of the parameter list explicitly.
-
pascal: Parameters are pushed on the stack left-to-right, and the callee is responsible for stack balancing.
-
stdcall: A variation of pascal where the callee handles stack cleanup, with arguments pushed right-to-left as in cdecl.
-
fastcall: The first two arguments are passed in specific registers, and remaining arguments are pushed on the stack.
-
vectorcall: Designed for efficient passing of vector arguments using SIMD registers.
-
safecall: Used in COM (Component Object Model) contexts to handle exceptions transparently.
-
Microsoft X64 Calling Convention: A standardized convention used on Windows and pre-boot UEFI for x86-64 architectures, utilizing specific registers for arguments and floating point values and employing a "shadow space" for stack handling.
Detailed Descriptions
For a comprehensive overview of these calling conventions, refer to the following resources:
- Wikipedia: [C calling conventions](https://en.wikipedia.org/wiki/X86_calling_conventions)
- MSDN: [Calling Conventions for C Compilers](https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention)
- Intel: [Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 1: Basic Architecture](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325383.pdf)
The above is the detailed content of How do different calling conventions impact function argument passing and stack cleanup in C/C ?. For more information, please follow other related articles on the PHP Chinese website!