Re: calling convention stdcalll and cdecl call
* Liviu:
"Alf P. Steinbach" <alfps@start.no> wrote in message
news:FrydnQFAxMIkhhzVnZ2dnUVZ_hadnZ2d@posted.comnet...
* Liviu:
"Alf P. Steinbach" <alfps@start.no> wrote
It had to do with a minor point that Igor may or may not have been
trying to make, who knows since evidently he doesn't mean what he
writes.
I'll go on a limb here ;-) but I trust Igor meant exactly what he
wrote:
| 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 requoted his claim above. What part exactly do you find incorrect?
"and thus cannot take variable number of parameters" is incorrect.
Please explain how a function which "must know how many
parameters there are" does, in fact, know that when called with a
variable number thereof.
An example would suffice...
You have already C++ and assembly language example, from earlier in this thread.
; this is the caller code ........................................
; calling a variadic _stdcall function with 1 argument
push eax
call _printf
; calling the same variadic _stdcall function with 2 arguments
push eax
push eax
call _printf
; ...etc
; please fill in this part ........................................
_printf:
; --- your code here ---
; --- doesn't have to do anything except _not_ corrupt the stack ---
Please note that once you impose additional requirements on the caller
code (pass number of params, set some sort of stack frame, etc) then
that's no longer the __stdcall convention.
Also, you must appreciate that __stdcall is just the C name for a well
defined binary contract between caller and callee. It is not a matter of
compiler, and there doesn't even have to be one involved. I could
technically write assembler, or direct machine bytecodes in debug.exe if
I so wished, and the same calling convention would still apply.
You asked this earlier and had it explained to you, in message
<mOednStCze1YgxzVnZ2dnUVZ_jSdnZ2d@posted.comnet>. Quoting from that message:
[Quoted from earlier message:]
Imagine for a moment that you'd be writing the __stdcall printf(const
char *, ...) code. At the point your code would be entered, everything
would look _exactly_ the same when the function is called in either of
these ways:
printf("%d", 1);
printf("%d", 1, 2);
How would you code your printf so that it pops the right number of bytes
off the stack in each case?
No problem. The number of bytes is passed in any way the compiler deems suitable
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?