问题
Does anybody know how variable arguments are passed in classic C? I did some debugging today and most regular arguments are passed via stack. However it seems that this does not apply for variable arguments. Are those parameters stored somewhere else like constant strings?
Thanks in advance!
回答1:
They are very often passed on the stack. What you are looking for is ABI specifications for the platform you are using.
For the AMD64 platform, have a look for example here.
回答2:
It depends on the platform. /usr/include/stdarg.h
is the place to start looking for details.
回答3:
You meant Variable-Length Argument Lists?
回答4:
Here's a fun trick
void func(type* values) {
while(*values) {
x = *values++;
/* do whatever with x */
}
}
func((type[]){val1,val2,val3,val4,0});
来源:https://stackoverflow.com/questions/5505344/passing-of-variable-arguments-in-c