Home > Backend Development > C++ > body text

How Do Calling Conventions Shape Function Argument Passing in C/C ?

DDD
Release: 2024-11-12 07:34:02
Original
1008 people have browsed it

How Do Calling Conventions Shape Function Argument Passing in C/C  ?

Understanding Calling Conventions in C/C

Calling conventions define how functions pass and receive arguments and their values. C/C offers various calling conventions, each serving a specific purpose.

Number of Calling Conventions

There are several calling conventions available in C/C , including:

  • cdecl
  • syscall
  • pascal
  • stdcall
  • fastcall
  • vectorcall
  • safecall
  • Microsoft X64 Calling Convention

Meaning of Each Convention

cdecl:

  • Arguments passed on the stack.
  • Registers are designated for specific purposes (EAX for return value, EAX, ECX, EDX for caller-saved).

syscall:

  • Similar to cdecl but does not preserve specific registers.

pascal:

  • Parameters passed on the stack in left-to-right order.
  • Callee responsible for stack cleanup.

stdcall:

  • Callee cleans up the stack.
  • Parameters pushed in right-to-left order, like cdecl.
  • Registers designated for internal function use (EAX, ECX, EDX).

fastcall:

  • First two arguments passed in registers (ECX and EDX).
  • Remaining arguments pushed on the stack right-to-left.

vectorcall:

  • Supports passing vector arguments using SIMD registers.
  • Up to six registers allocated for vector arguments.

safecall (Delphi/Free Pascal):

  • Encapsulates COM error handling.
  • Exceptions returned in EAX as an HRESULT, while the result is passed by reference.

Microsoft X64 Calling Convention:

  • Used in Windows and pre-boot UEFI.
  • First four integer/pointer arguments passed in registers (RCX, RDX, R8, R9).

The above is the detailed content of How Do Calling Conventions Shape Function Argument Passing in C/C ?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template