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...
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...
Originally Posted by sunil21You 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
Help everyone you can
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.
Last edited by iwabee; 08-21-2004 at 08:16 AM.
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
"Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
-- Cowper
Operating Systems=Slackware Linux 9.1,Windows 98/Xp
Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)
You may teach a person from now until doom's day, but that person will only know what he learns himself.
Now I know what doesn't work.
A problem is understood by solving it, not by pondering it.
For a bit of humor check out xkcd web comic http://xkcd.com/235/
Ok, Thank you... Learnt a new thing now.....
Help everyone you can