Re: stdcall / cdecl -- please clarify
- Posted by Robert Craig <rds at RapidEuphoria.com> Feb 12, 2002
- 598 views
C.K. Lester writes: > Can somebody explain what a stdcall routine is vs. a cdecl routine? In the beginning, Microsoft created the __stdcall "standard call" calling convention for C subroutines. Later, ANSI C and C++ decided to support the passing of variable numbers of arguments to routines. i.e. one call to foo() might pass 3 arguments, while another call to foo() passes 6 arguments. The problem was __stdcall couldn't handle variable numbers of arguments, because in __stdcall, the subroutine is required to pop the arguments off the stack at the end of a call, but with variable numbers of args it can't always be sure how many arguments were passed, so it doesn't know how many to pop. Only the caller knows for sure how many arguments were passed, so the caller must adjust the stack pointer register. This led to the __cdecl calling convention, where the caller gets to pop the arguments. Unfortunately, tons of code was already "out there" that used __stdcall, in particular all those Windows apps that call the WIN32 API. So now Windows C programmers have to be aware of two different calling conventions, and just to make it more obscure, there are usually alternate names defined for these calling conventions, such as EXPORT or WINAPI or CALLBACK or whatever. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com