开发者

Passing of variable arguments in C

开发者 https://www.devze.com 2023-02-21 10:06 出处:网络
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 f

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});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号