Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

like image 721
lucastamoios Avatar asked Oct 26 '12 15:10

lucastamoios


People also ask

When should I use Fastcall?

Use the __fastcall modifier to declare functions that expect parameters to be passed in registers. The first three parameters are passed (from left to right) in EAX, EDX, and ECX, if they fit in the register. The registers are not used if the parameter is a floating-point or struct type.

Is Fastcall faster?

Since it typically saves at least four memory accesses, yes it is generally faster.

What is the difference between Stdcall and cdecl?

In CDECL arguments are pushed onto the stack in revers order, the caller clears the stack and result is returned via processor registry (later I will call it "register A"). In STDCALL there is one difference, the caller doeasn't clear the stack, the calle do.

What is __ Fastcall in C++?

The __fastcall calling convention specifies that arguments to functions are to be passed in registers, when possible. This calling convention only applies to the x86 architecture.


1 Answers

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

like image 105
Daniel Gehriger Avatar answered Sep 17 '22 15:09

Daniel Gehriger