__cdecl, __stdcall and __fastcall are all called the same?

I am using Visual C ++ 2010 and MASM as x64-Assembler.
This is my C ++ code:

// include directive #include "stdafx.h" // functions extern "C" int Asm(); extern "C" int (convention) sum(int x, int y) { return x + y; } // main function int main() { // print asm printf("Asm returned %d.\n", Asm()); // get char, return _getch(); return EXIT_SUCCESS; } 

And my build code:

 ; external functions extern sum : proc ; code segment .code Asm proc ; create shadow space sub rsp, 20o ; setup parameters mov ecx, 10 mov edx, 15 ; call call sum ; clean-up shadow space add rsp, 20o ; return ret Asm endp end 

The reason I do this is because I can find out different calling conventions. I would make a call to the sumdcall call and change the asm code so that it calls the sum "stdcall". As soon as I get this work, I will do it, say fastcall, and then call it in asm the fastcall method.

But look at my build code right now. When I use this code, regardless of whether the sum is stdcall, fastcall or cdecl, it will compile, execute a fine and print 25 as my sum.

My question is: how and why __cdecl, __stdcall and __fastcall can all be called in exactly the same way?

+7
source share
2 answers

The problem is that you are compiling for x64 purposes. From MSDN

Given an extended set of registers, x64 simply uses the __fastcall convention call and the RISC-based exception handling model. The __fastcall model uses registers for the first four arguments and the stack frame to pass other parameters.

Switch to compilation for x86 purposes, and you can see the various calling conventions in action.

+10
source

As far as I know, x64 only uses the __fastcall convention. __cdecl and stdcall will only compile as __fastcall.

+3
source

All Articles