Search code examples
cx86calling-conventioncdeclfastcall

Why should I not use __fastcall instead the standard __cdecl?


I'd listening some people saying __fastcall is faster than __cdecl and __stdcall cause it puts two parameters in register, instead of the one of other calls; but, in other hand, this is not the standard used in C.

I would like to know what makes __fastcall undesirable like a standard in C and when I will use this in my code.


Solution

  • The x86 platform is unusual in that it doesn't define a global ABI and calling convention.

    Win32/x86 does, it standardizes on stdcall. There are various tradeoffs between calling conventions -- placing parameters in registers is faster, but it forces the caller to spill whatever was previously using those registers. So it's hard to predict which gives better performance.

    The important thing is to have a uniform standard calling convention to enable interoperability between different compilers (and even different programming languages).

    Other platforms don't have cdecl, stdcall, or fastcall conventions. They don't have the same set of registers. In some cases, they don't even have registers at all. But they still can use C code.

    Win32/x86_64 doesn't use stdcall, it uses a 64-bit extension of fastcall.

    Linux/x86 has a convention also.