A calling convention refers to the way a function transmits parameters to a called function and receives a return value from it.
Questions tagged [calling-convention]
1051 questions
194
votes
4 answers
What are the calling conventions for UNIX & Linux system calls (and user-space functions) on i386 and x86-64
Following links explain x86-32 system call conventions for both UNIX (BSD flavor) & Linux:
http://www.int80h.org/bsdasm/#system-calls
http://www.freebsd.org/doc/en/books/developers-handbook/x86-system-calls.html
But what are the x86-64 system call…

claws
- 52,236
- 58
- 146
- 195
176
votes
8 answers
What is __stdcall?
I'm learning about Win32 programming, and the WinMain prototype looks like:
int WINAPI WinMain ( HINSTANCE instance, HINSTANCE prev_instance, PSTR cmd_line, int cmd_show )
I was confused as to what this WINAPI identifier was for and found:
#define…

Tristan Havelick
- 67,400
- 20
- 54
- 64
137
votes
4 answers
Why does Windows64 use a different calling convention from all other OSes on x86-64?
AMD has an ABI specification that describes the calling convention to use on x86-64. All OSes follow it, except for Windows which has it's own x86-64 calling convention. Why?
Does anyone know the technical, historical, or political reasons for this…

JanKanis
- 6,346
- 5
- 38
- 42
127
votes
7 answers
How exactly does the callstack work?
I'm trying to get a deeper understanding of how the low level operations of programming languages work and especially how they interact with the OS/CPU. I've probably read every answer in every stack/heap related thread here on Stack Overflow, and…

Christoph
- 26,519
- 28
- 95
- 133
104
votes
4 answers
Why can a T* be passed in register, but a unique_ptr cannot?
I'm watching Chandler Carruth's talk in CppCon 2019:
There are no Zero-Cost Abstractions
in it, he gives the example of how he was surprised by just how much overhead you incur by using an std::unique_ptr over an int*; that segment starts about…

einpoklum
- 118,144
- 57
- 340
- 684
91
votes
3 answers
__cdecl or __stdcall on Windows?
I'm currently developing a C++ library for Windows which will be distributed as a DLL. My goal is to maximize binary interoperability; more precisely, the functions in my DLL must be usable from code compiled with multiple versions of MSVC++ and…

Etienne Dechamps
- 24,037
- 4
- 32
- 31
90
votes
9 answers
What is the meaning and usage of __stdcall?
I've come across __stdcall a lot these days.
MSDN doesn't explain very clearly what it really means, when and why should it be used, if at all.
I would appreciate if someone would provide an explanation, preferably with an example or two.

vehomzzz
- 42,832
- 72
- 186
- 216
88
votes
3 answers
Where is the x86-64 System V ABI documented?
The x86-64 System V ABI (used on everything except Windows) used to live at http://x86-64.org/documentation/abi.pdf, but that site has now fallen off the internet.
Is there a new authoritative home for the document?

Jeffrey Yasskin
- 5,171
- 2
- 27
- 39
77
votes
6 answers
What are callee and caller saved registers?
I'm having some trouble understanding the difference between caller and callee saved registers and when to use what.
I am using the MSP430
:
procedure:
mov.w #0,R7
mov.w #0,R6
add.w R6,R7
inc.w R6
cmp.w R12,R6
jl l$loop
mov.w R7,R12
ret
the…

mugetsu
- 4,228
- 9
- 50
- 79
76
votes
7 answers
Retrieving the calling method name from within a method
I have a method in an object that is called from a number of places within the object. Is there a quick and easy way to get the name of the method that called this popular method.
Pseudo Code EXAMPLE:
public Main()
{
PopularMethod();
}
public…
user26901
66
votes
6 answers
What registers to save in the ARM C calling convention?
It's been a while since I last coded arm assembler and I'm a little rusty on the details. If I call a C function from arm, I only have to worry about saving r0-r3 and lr, right?
If the C function uses any other registers, is it responsible for…

richq
- 55,548
- 20
- 150
- 144
61
votes
3 answers
What registers are preserved through a linux x86-64 function call
I believe I understand how the linux x86-64 ABI uses registers and stack to pass parameters to a function (cf. previous ABI discussion). What I'm confused about is if/what registers are expected to be preserved across a function call. That is, what…

boneheadgeek
- 765
- 1
- 7
- 9
55
votes
3 answers
Why is %eax zeroed before a call to printf?
I am trying to pick up a little x86. I am compiling on a 64bit mac with gcc -S -O0.
Code in C:
printf("%d", 1);
Output:
movl $1, %esi
leaq LC0(%rip), %rdi
movl $0, %eax ; WHY?
call _printf
I do not understand why %eax is cleared…

sh54
- 1,230
- 1
- 11
- 20
54
votes
20 answers
Weird MSC 8.0 error: "The value of ESP was not properly saved across a function call..."
We recently attempted to break apart some of our Visual Studio projects into libraries, and everything seemed to compile and build fine in a test project with one of the library projects as a dependency. However, attempting to run the application…

user11180
- 751
- 2
- 6
- 5
53
votes
8 answers
Pass function as a parameter
I've written function 'A' that will call one of a number of other functions. To save re-writing function 'A', I'd like to pass the function to be called as a parameter of function 'A'. For example:
function A{
Param($functionToCall)
…

woter324
- 2,608
- 5
- 27
- 47