Home

cdecl

Cdecl is a calling convention used by C and C++ on x86 processors that specifies how functions receive arguments, return values, and how the call stack is managed. Under cdecl, function arguments are pushed onto the stack from right to left, and the caller is responsible for cleaning the stack after the call. The callee should not adjust the stack pointer to remove arguments.

Return values: for most integer and pointer types, the result is returned in the EAX register. Floating-point

Register usage and prologue/epilogue: the callee must preserve certain registers (commonly EBX, ESI, EDI, and EBP)

Variadic support: cdecl is well suited for functions with a variable number of arguments, such as printf,

Platform notes: cdecl is mainly associated with 32-bit x86 code and is widely supported by compilers like

In summary, cdecl defines a widely used, flexible model for x86 function calls, emphasizing right-to-left argument

results
may
be
returned
in
an
FPU
register
or
an
SSE
register
depending
on
the
compiler
and
ABI.
The
exact
handling
of
larger
or
structure
returns
depends
on
the
platform
and
compiler.
across
calls,
while
other
registers
are
caller-saved.
A
typical
function
prologue
uses
a
stack
frame
(push
EBP;
mov
EBP,
ESP;
sub
ESP,
...),
and
the
epilogue
restores
the
frame
and
returns
(leave;
ret).
Because
the
caller
cleans
the
stack,
the
callee
does
not
know
how
many
arguments
were
passed,
enabling
variadic
functions.
since
the
caller
controls
stack
cleanup
and
argument
counting.
GCC
and
Clang,
as
well
as
many
environments
in
the
past.
On
64-bit
platforms,
modern
ABIs
(such
as
System
V
AMD64
and
Windows
x64)
use
different
conventions,
and
cdecl
is
not
the
default
there.
Symbol
naming
and
decoration
can
vary
by
compiler
and
platform,
but
the
convention
itself
centers
on
who
cleans
the
stack
and
how
arguments
are
passed.
passing,
caller-managed
stack
cleanup,
and
consistent
return
value
handling.