Questions tagged [calling-convention]

A calling convention refers to the way a function transmits parameters to a called function and receives a return value from it.

1051 questions
45
votes
1 answer

How to declare an __stdcall function pointer

I tried this typedef void (* __stdcall MessageHandler)(const Task*); This compiles but gives me this warning (VS2003): warning C4229: anachronism used : modifiers on data are ignored I want to declare a pointer to a function with stdcall…
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
44
votes
4 answers

Is fastcall really faster?

Is the fastcall calling convention really faster than other calling conventions, such as cdecl? Are there any benchmarks out there that show how performance is affected by calling convention?
zr.
  • 7,528
  • 11
  • 50
  • 84
43
votes
2 answers

What is the 'shadow space' in x64 assembly?

I found plenty of topics about this shadow space, but I couldn't find the answer in none of them, so my question is: How much exactly bytes I need to subtract from the stack pointer, before entering to a procedure? And should I push the procedure…
Igor Bezverhi
  • 483
  • 1
  • 5
  • 11
41
votes
8 answers

What does "cdecl" stand for?

Yes, I know that "cdecl" is the name of a prominent calling convention, so please don't explain calling conventions to me. What I'm asking is what the abbreviation (?) "cdecl" actually stands for. I think it's a poor naming choice, because at first…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
34
votes
6 answers

What are the different calling conventions in C/C++ and what do each mean?

There are different calling conventions available in C/C++: stdcall, extern, pascal, etc. How many such calling conventions are available, and what do each mean? Are there any links that describe these?
Prabhu R
  • 13,836
  • 21
  • 78
  • 112
34
votes
10 answers

Why does the Mac ABI require 16-byte stack alignment for x86-32?

I can understand this requirement for the old PPC RISC systems and even for x86-64, but for the old tried-and-true x86? In this case, the stack needs to be aligned on 4 byte boundaries only. Yes, some of the MMX/SSE instructions require 16byte…
Allen Bauer
  • 16,657
  • 2
  • 56
  • 74
34
votes
2 answers

Where exactly is the red zone on x86-64?

From Wikipedia: In computing, a red zone is a fixed-size area in a function's stack frame beyond the return address which is not preserved by that function. The callee function may use the red zone for storing local variables without the extra…
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
33
votes
1 answer

Array initialization optimization

When compiling the following code snippet (clang x86-64 -O3) std::array test() { std::array values {{0, 1, 2, 3, 4}}; return values; } It produced the typical assembly that I would expect test(): …
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
31
votes
3 answers

How are variable arguments implemented in gcc?

int max(int n, ...) I am using cdecl calling convention where the caller cleans up the variable after the callee returns. I am interested in knowing how do the macros va_end, va_start and va_arg work? Does the caller pass in the address of the…
Bruce
  • 33,927
  • 76
  • 174
  • 262
29
votes
2 answers

Why does std::tuple break small-size struct calling convention optimization in C++?

C++ has a small-size struct calling convention optimization where the compiler passes a small-size struct in function parameters as efficiently as it passes a primitive type (say, via registers). For example: class MyInt { int n; public: MyInt(int…
YumeYao
  • 557
  • 4
  • 10
28
votes
3 answers

Can Scala call by reference?

I know that Scala supports call-by-name from ALGOL, and I think I understand what that means, but can Scala do call-by-reference like C#, VB.NET, and C++ can? I know that Java cannot do call-by-reference, but I'm unsure if this limitation is solely…
royco
  • 5,409
  • 13
  • 60
  • 84
28
votes
5 answers

How do C compilers implement functions that return large structures?

The return value of a function is usually stored on the stack or in a register. But for a large structure, it has to be on the stack. How much copying has to happen in a real compiler for this code? Or is it optimized away? For example: struct Data…
Steve Hanov
  • 11,316
  • 16
  • 62
  • 69
27
votes
3 answers

Function pointer and calling convention

float __stdcall (*pFunc)(float a, float b) = (float (__stdcall *)(float,float))0x411280; How to declare a function pointer with calling convention? The above gives me an error.
Yulo
  • 291
  • 1
  • 3
  • 4
27
votes
4 answers

How to "goto" into different function in c?

Basically I am trying to simulate assembly code in C. Here is the C code: int main() { test(); main_next: printf("Hello, World!"); } void test() { goto main_next; } Trying to compile this code (Linux 32 bit, gcc 4.6.3), I got this…
lllllllllllll
  • 8,519
  • 9
  • 45
  • 80
25
votes
1 answer

Why is EAX being cleared before calling a function if I don't include the header?

In the following C code: #include int main(void){getchar();} It produces the following asm: main: push rbp mov rbp, rsp # no extra instruction here when header is included call getchar …
carl.hiass
  • 1,526
  • 1
  • 6
  • 26
1
2
3
69 70