From: SourceForge.net <no...@so...> - 2004-05-21 03:23:05
|
Read and respond to this message at: https://sourceforge.net/forum/message.php?msg_id=2579615 By: adah > In the standard C calling convention (__cdecl), the parameters are pushed > from right to left, and the caller must clear the stack after the call. > In the other calling conventions (__stdcall, __pascal, etc), the parameters > are pushed from left to right, and the called routine removes arguments from > the stack. No, that is not right. According to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_ core___stdcall.asp __stdcall pushes arguments from right to left. The difference between __cdecl is who in responsible for pop up the arguments. > (And my program should crash if there is a mismatch between the calling and > the called conventions !) The program did not crash on mismatch because the ESP is restored from EBP when the function returns. You will not be so lucky when the -fomit-frame-pointer optimization is used. > void __pascal push() {} > typedef void (__pascal * PUSHLONG)( long ); > PUSHLONG pushFn = (PUSHLONG) push; > pushFn( a ); > pushFn( b ); > // a & b are now on the stack > lResult = FnPtr(); // or (* FnPtr)() > > With MinGW, no argument is passed to the called routine ! (while it is OK > with other compilers) __pascal is simply defined to __stdcall. And I guess the stack trick did not work because of the same reason why you program did not crash. Please do not mail to me personally. Thanks. ______________________________________________________________________ You are receiving this email because you elected to monitor this forum. To stop monitoring this forum, login to SourceForge.net and visit: https://sourceforge.net/forum/unmonitor.php?forum_id=7134 |