Question

I'd listening some people saying __fastcall is faster than __cdecl and __stdcall cause it put 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.

Was it helpful?

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 the architecture-defined convention.

Linux/x86 has a convention also.

OTHER TIPS

Are you looking for a calling convention to specify for a library interface? Because for all other functions, I wouldn't specify a calling convention at all. The compiler's optimization pass (auto-inlining for instance) probably renders the calling convention useless.

But regarding fastcall: as far as I remember, it's not standardized, and therefore not suitable for library code. Here is nice overview: Calling Conventions Demystified

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top