Quote Originally Posted by Salem View Post
> If the callee can determine the number of actual parameters passed (for example, printf uses the format string to determine that),
Are you sure?
Code:
printf( "This is my int %d\n", 1, 2, 3, 4, 5 );
Whilst being dumb, it isn't fatal. So long as the n conversions in the format string are matched by at least n compatible values, all is well.

> how does it know how many parameters it can access?
It doesn't.
Code:
printf( "This is my int %d\n" );
will try to read an int anyway from where the next parameter is expected to be.

Without a strong type-check to enforce a bunch of rules for variadic functions, it's quite hard work for the callee to work out how many real parameters there are.
Ah I see now. Thanks.

If you're using a compiler, it doesn't matter.
But it does matter if you are trying to interface asm to compiler-generated code.

The x86 core has a feature called "esp folding" which allows the processor to delay making visible changes to esp when it is altered implicitly by push and pop instructions. An explicit argument cleanup, by adding a constant value to esp, interferes with this deferral and causes pipeline stalls.

The fewer times you modify the value of esp explicitly, the better. There is more going on in these instructions than meets the eye.
Ah, so does that mean if there are only a few parameters, doing a few pops (to an unused register) may be faster than an add to esp?