Passing variable number of arguments around

前端 未结 11 841
我寻月下人不归
我寻月下人不归 2020-11-22 07:16

Say I have a C function which takes a variable number of arguments: How can I call another function which expects a variable number of arguments from inside of it, passing a

11条回答
  •  星月不相逢
    2020-11-22 07:50

    Variadic Functions can be dangerous. Here's a safer trick:

       void func(type* values) {
            while(*values) {
                x = *values++;
                /* do whatever with x */
            }
        }
    
    func((type[]){val1,val2,val3,val4,0});
    

提交回复
热议问题