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?
Aaron
source share