i have this somewhere
" In __cdecl functions, arguments are pushed right to left and the caller is responsible for cleaning up the stack "
What actually is it.
Can we use _cdecl in out function prototyping...
Printable View
i have this somewhere
" In __cdecl functions, arguments are pushed right to left and the caller is responsible for cleaning up the stack "
What actually is it.
Can we use _cdecl in out function prototyping...
Quote:
Originally Posted by sunil21
You see, left to right and right to left. And foo() will "pop" arguments (cleans the stack) before returning.Code:void foo(int a1, int a2, int a3);
if you disassemble your code you will see, that _cdcel and _stdcall look like that.
_cdcel call:
__asm
{
push a1
push a2
push a3
call foo
}
_stdcall call:
__asm
{
push a3
push a2
push a1
call foo
}
}
What is the relative advantage in each case? Also, what is meant by the line "and the caller is responsible for cleaning up the stack" in case of _cdecl? Does that mean in _stdcall's case cleaning of stack is not required (then, will the compiler insert the code to do it?).?
-Harsha
There's almost no advantage in any case. That's why they are called conventions and not some methods or something. The only difference is that if you calling lot's of external functions (like Win32 API) your code will be few bytes shorter (3 bytes per function call).
If you have pushed something in stack you have to clean it up, otherwise you'd have stack overflow pretty soon. Usually it's done by "add esp, <number of bytes>", but line can be in caller or callee. In case of _cdcel it's caller (with exeption of functions that take "..." as argument), and in case of _stdcall it's callee.
Edit: you don't have to insert any code if you are not using assembly. you just have to specify wich convention function uses and compiler will do the rest.
There are certain functions that have a varaible argument list such as printf(). With the cdecl it allows you create functions that take a variable arguement list. however
" The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code" --MSDN library
http://msdn.microsoft.com/library/de...re___cdecl.asp
Ok, Thank you... Learnt a new thing now.....
:)