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
24
votes
9 answers
Why should default parameters be added last in C++ functions?
Why should default parameters be added last in C++ functions?

yesraaj
- 46,370
- 69
- 194
- 251
23
votes
2 answers
Why can I invoke a function via a pointer with too many arguments?
Say I have this function:
int func2() {
printf("func2\n");
return 0;
}
Now I declare a pointer:
int (*fp)(double);
This should point to a function that takes a double argument and returns an int.
func2 does NOT have any argument, but still…

yotamoo
- 5,334
- 13
- 49
- 61
23
votes
1 answer
Changing a C# delegate's calling convention to CDECL
I have had this problem with C# when I was using DotNet1.1
The problem is this. I have an unmanaged dll, which has a function which takes a function pointer (among other arguments). When I declare the DLLImport in C# code, I pass a delegate. But the…

Armen Tsirunyan
- 130,161
- 59
- 324
- 434
22
votes
1 answer
Is returning a 2-tuple less efficient than std::pair?
Consider this code:
#include
#include
std::pair f1()
{
return std::make_pair(0x111, 0x222);
}
std::tuple f2()
{
return std::make_tuple(0x111, 0x222);
}
Clang 3 and 4 generate similar code for both on…

John Zwinck
- 239,568
- 38
- 324
- 436
21
votes
1 answer
how to specify vc11 lambda calling convention
I want to pass a lambda function pointer, which nested in a class, to the Windows API callback function. I found there is no place for me to specify the __stdcall keyword. Some people told me the compile only support __cdecl, but after I used nm…

andrew young
- 231
- 2
- 5
20
votes
3 answers
What registers must be preserved by an x86 function?
I'm writing a function in x86 assembly that should be callable from c code, and I'm wondering which registers i have to restore before i return to the caller.
Currently I'm only restoring esp and ebp, while the return value is in eax.
Are there any…

bobbaluba
- 3,584
- 2
- 31
- 45
20
votes
1 answer
Are we Overusing Pass-by-Pointer in Go?
This question is specific to function calls, and is directed towards the trustworthiness of the Go optimizer when passing structs by value vs by pointer.
If you're wondering when to use values vs pointers in struct fields, see: Go - Performance -…

Kent
- 713
- 2
- 8
- 19
19
votes
2 answers
Is reserving stack space necessary for functions less than four arguments?
Just started learning x64 assembly and I have a question about functions, arguments, and the stack. As far as I understand it, the first four arguments in a function get passed to rcx, rdx, r8, and r9 registers (and xmm0-xmm3 for floats) in…

Don
- 275
- 5
- 14
19
votes
2 answers
C: Return value via stack/register question
I am new to C, and there is one thing I can not understand.
When function returns something that is not bigger than register -- my compiler puts it in EAX.
When I return big structure (not pointer but structure itself) -- it is returned via…

Ilya
- 201
- 1
- 2
- 4
19
votes
4 answers
Why does gcc use movl instead of push to pass function args?
pay attention to this code :
#include
void a(int a, int b, int c)
{
char buffer1[5];
char buffer2[10];
}
int main()
{
a(1,2,3);
}
after that :
gcc -S a.c
that command shows our source code in assembly.
now we can see in…

Pooya
- 992
- 2
- 10
- 31
19
votes
1 answer
where is amd64 psABI?
The AMD64 psABI used to be hosted at x86-64.org.
I have a copy of pdf file and it says explicitly:
The architecture specification is available on the web at
http://www.x86-64.org/documentation.
but http://www.x86-64.org is down for a long time…

Alexander Gorshenev
- 2,769
- 18
- 33
19
votes
3 answers
Is "asmlinkage" required for a c function to be called from assembly?
I am writing a C function that will be invoked from assembly code.
(Specifically, I want to do some checking job in the path of system call handling in linux kernel, so I will call the c function before a system call is dispatched in entry_32.S)
I…

Infinite
- 3,198
- 4
- 27
- 36
17
votes
2 answers
Why not store function parameters in XMM vector registers?
I'm currently reading the book: "Computer Systems - A Programmers Perspective". I've found out that, on the x86-64 architecture, we are limited to 6 integral parameters which will be passed to a function in registers. The next parameters will be…

denis631
- 1,765
- 3
- 17
- 38
17
votes
1 answer
Why can't I specify the calling convention for a constructor(C++)?
In Visual Studio 2013 a new calling convention _vectorcall exists. It is intended for usage with SSE data types that can be passed in SSE registers.
You can specify the calling convention of a member functions like so.
struct Vector{//a 16 byte…

Froglegs
- 1,095
- 1
- 11
- 21
17
votes
2 answers
What's the default calling convention of a C++ lambda function?
The following code was compiled with VC++ 2012:
void f1(void (__stdcall *)())
{}
void f2(void (__cdecl *)())
{}
void __cdecl h1()
{}
void __stdcall h2()
{}
int main()
{
f1(h1); // error C2664
f2(h2); // error C2664
f1([](){}); //…

xmllmx
- 39,765
- 26
- 162
- 323