Speaking of C++
-
That's a very interesting point, because I just assumed that C's default convention was
stdapi
. The reason I assumed that is that when you want to export a function from a C++ DLL, you usually enclose the declaration inextern "C"
. But I never considered that C's default convention was cdecl. Well played. :)The difficult we do right away... ...the impossible takes slightly longer.
-
Quote:
Windows was from the beginning designed to be programmed in C.
That is true if you never opened a window before it became 32 bits. The native calling convention of the original 16 bits Windows was the Pascal way of doing it.
1. The Windows SDK was always published first in C. If any ports to other languages occurred (e.g. Borland's Borland Pascal), they were delayed by some months. 2. As my OP said, the calling convention is handled by the C compiler, so unless you are programming in Assembly language, it is irrelevant. I stand by my statement.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
-
What is the theory behind making the default calling convention
cdecl
? It leads to larger code and it's fundamentally incompatible with OS APIs. What were they thinking?The difficult we do right away... ...the impossible takes slightly longer.
C existed during 16 bit period and I am almost sure that
RET
instruction did not take argument back then. Your computer most likely start in real mode, which is 16 bit, so it is still in use today. I suppose that is why they do not want to change the calling convention. P.S. fastcall prolog is usually optimized (under /O2 or more) to use arguments directly from registers when possible. -
extern "C" indicates that C++ name mangling should not be used - just the plain function name, not decorated with the types of the function arguments for overload resolution.
Your partly correct, indeed it indicates that C++ name mangling should not be used. But this does not mean plain function names. It's mangling the way c get's mangled. For example a function returning a 32 bit int would be something like function@4 and if u take stdcall c function by a microsoft vc compiler u often get even more mangling on the function name.