Re: Calling Conventions

new topic     » goto parent     » topic index » view thread      » older message » newer message

Chris Bensler wrote:
> It is my understanding that cdecl functions require the caller to cleanup the
> stack, whereas the others are required to cleanup the stack themselves?

Yes.
 
> I'm working on some code for the various calling conventions using cprintf()
> as one of my test functions which is a variadic function and thus is sure to
> be cdecl. Another function I'm using is GetVersion() from the WINAPI which I'm
> quite positive is stdcall.
> 
> The asm I've create seems to work fine except that I had thought that the
> instruction
> "add esp, ebx" would have to be removed for stdcalls. Strangely, it works for
> both cdecl and stdcall if the instruction is present but crashes for both if
> it isn't.

I've found that code compiled by Watcom, such as exw.exe,
or translated code compiled by Watcom, is more or less immune
to crashing, even if you use the wrong calling convention 
(cdecl vs. stdcall). I confirmed this once by examining the 
actual machine code produced by Watcom. I don't remember off-hand 
exactly what the code sequence was, but it was somehow 
saving/restoring the stack pointer and avoiding a crash. 
This appeared to be just luck, not some clever plan.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu