There are (among others) two types of calling conventions - stdcall and cdecl. I have few questions on them:
a) When a cdecl function is called by the caller, how does a caller know if it should free up the stack?
The cdecl
modifier is part of the function prototype (or function pointer type etc.) so the caller get the info from there and acts accordingly.
b) If a function which is declared as stdcall calls a function(which has a calling convention as cdecl), or the other way round, would this be inappropriate?
No, it's fine.
c) In general, can we say that which call will be faster - cdecl or stdcall?
In general, I would refrain from any such statements. The distinction matters eg. when you want to use va_arg functions. In theory, it could be that stdcall
is faster and generates smaller code because it allows to combine popping the arguments with popping the locals, but OTOH with cdecl
, you can do the same thing, too, if you're clever.
The calling conventions that aim to be faster usually do some register-passing.