Passing of variable arguments in C
Does anybody know how variable arguments are passed in classic C? I did some debugging toda开发者_JAVA百科y 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!
It depends on the platform. /usr/include/stdarg.h
is the place to start looking for details.
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.
You meant Variable-Length Argument Lists?
Here's a fun trick
void func(type* values) {
while(*values) {
x = *values++;
/* do whatever with x */
}
}
func((type[]){val1,val2,val3,val4,0});
精彩评论