My question is simple like that, what is the diference?



eg, I can have a function for call like C like:

functC:

; alloc and dealloc locals and such things and the code sure
ret


And for call:


push arg3
push arg2
push arg1
call functC
add esp, 12


a std like funct will be:


functStd:
; alloc and dealloc locals and such things and the code sure
ret 12


And for call:


push arg3
push arg2
push arg1
call functStd



But what happend with a vararg?

with c call not much problem, still the same
funct2C:

; alloc and dealloc locals and such things and the code sure
ret

And for call it
push argn
....
push arg1
call funct2C
add esp, n*4
That is the diference that can pass more, but you still cleaning the stack


My principal question is what happend with the combination of stdcall and vararg, a proto or some like that will look like:

proto stdfunction, arg1, arg2, arg3, vararg

But what I know from stdcall (the only diference that I see with a C call is that the calle clean the stack), then following this, i have this definition of proto like this:



stdfunction:
push ebp
mov ebp, esp
;locals and code
mov esp, ebp
pop ebp
ret 16


Now you will question what!!!!! you are cleaning the stack with a vararg there!!!, the answer is yes, you dont need clean the stack if you pass exactly the minimun number of arguments that have the vararg function with stdcall, but you clean the excedent if a call to this function have more arguments than the minimun acepted, like this...



invk stdfunction, one, two, three, four ;this not cause the caller clean the excedent
invk stdfunction, one, two, three, four, five, six, seven, etc
add esp, 16


You see now what is my problem, because if a call to stdfunction with vararg will cause:


invk stdfunction, one, two, three, four
add esp, 16
invk stdfunction, one, two, three, four, five, six, seven, etc
add esp, 16+16


Because if this is the real expansion of a std function with vararg, then I really not see diference with the C call convention and a std with vararg, because is the same!!!!! is only then allowed diferent names for the same thing.... always clean the stack (completelly even if in the defintion of stdcall say that it clean is parameters before return ), I think this definition not need be overwrited by the use of vararg, like you see the stdcall cann still cleaning himself is arguments, but if extra arguments passed, the caller need clean them.. the extra arguments passed.



Ok, to much write for only question... Is there a diference between a C call and a stdcall with varargs???



Have a nice day or night.
Posted on 2004-01-05 01:05:20 by rea
from MASM help

* The STDCALL language type uses caller stack cleanup if the :VARARG
parameter is used. Otherwise, the called routine must clean up the
stack.

so the difference I think will be, that you have the choice to use VARARG.
If you use it, you clean the stack, if not, the function cleans the stack, and that option C convension does not have.
Posted on 2004-01-05 02:32:23 by Jnrz
Yes like a option.

But then, there is no diference when you aleady have a stdcall declared with var arg, and a ccall with (or without ) the vararg. Because the caller clean the stack.

proto isC C u1:dword, x:VARARG
proto std u1:dword, x:VARARG

and:

invk isC, one, two, three
add esp, 12
invk std, uno, two, three
add esp, 12


Ok, I was thinking that for example "invk std, one, two" will not generate align by the caller and "std, uno, two, three" will cause a extra align by the caller like "add esp, 4", because the std that WAS stdcall continue cleaning his 'direct arguments' that was 2.. or ret 8.


Have a nice day or night.
Posted on 2004-01-05 03:45:01 by rea