Passing of variable arguments in C

非 Y 不嫁゛ 提交于 2019-12-12 19:20:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!