Tuesday, August 19, 2008

Difference between __cdecl and __stdcall

The Microsoft compiler offers two calling coventions one __cdecl (Standard C calling convention) and the other __stdcall. All of the windows system calls are implemented using the __stdcall calling convention.

In case of __cdecl
1) It is possible to pass a variable argument (parameter) list (Standard C requirement)
2) As a result the calling function is suppose to clean up the arguments (parameters) of the stack. Since it is just the calling function which knows the exact number of argument bytes.

In case of __stdcall
1) It is not possible to pass a variable argument (parameter) list
2) As the number of arguments are known at compile time, it is possible to pass the information regarding the number of parameters on the stack to the called function. The called function can then itself perform the stack cleanup before returning.

As a result the __stdcall results in a more compact code since the called function performs the stack cleanup instead of each calling function doing it, there by saving few bytes per calling function. There by making the code tiny bit faster as well.

Labels:

0 Comments:

Post a Comment

<< Home