Re: calling convention stdcalll and cdecl call



"Alf P. Steinbach" <alfps@xxxxxxxx> wrote in message
news:XMudnXxazN5UzR3VnZ2dnUVZ_oWdnZ2d@xxxxxxxxxxxxx
* Igor Tandetnik:
With stdcall, the function is responsible for removing its parameters
from the stack. To do this, it must know how many parameters there
are, and thus cannot take variable number of parameters.

I'm sorry, that's incorrect (counter-example below).

Your example uses additional domain-specific information that the
compiler doesn't have, in general: that the first parameter specifies
the total number of remaining parameters, and that all parameters are
the same size.

Or are you suggesting that the caller should pass the total size of all
parameters as a hidden first parameter? That defeats the whole point of
__stdcall convention, which is to shave one machine instruction off the
call site. If you are willing to push the size of parameters onto the
stack before the call, you can just as well update ESP after the call
instead - at which point you are happily back in __cdecl land.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: calling convention stdcalll and cdecl call
    ... Igor Tandetnik: ... that the first parameter specifies the total number of remaining parameters, ... If you are willing to push the size of parameters onto the stack before the call, you can just as well update ESP after the call instead - at which point you are happily back in __cdecl land. ... I'm sorry, but there's no connection between premise and conclusion, and the conclusion is wrong (e.g. printf is a counter-example). ...
    (microsoft.public.vc.language)
  • Re: BSOD restoring from Hibernation in XP Pro SP2
    ... kernel stack inpage error ... stack was not found. ... If the first parameter is 2, the driver stack returned an inconsistent ...
    (microsoft.public.windowsxp.hardware)
  • Re: Function order of execution
    ... This may be a WAD, ... one can not simply "push" the first parameter onto the ... stack to hold it and then pop it back into EAX. ...
    (borland.public.delphi.language.objectpascal)