How can I call (not define) a function with a variable number of arguments in C?

前端 未结 6 1753
感情败类
感情败类 2021-01-20 01:05

Is there any way to make this code shorter?

long call_f(int argc, long *argv) {
  switch (argc) {
    case 0:
      return f();
      break;
    case 1:
             


        
6条回答
  •  -上瘾入骨i
    2021-01-20 01:18

    I don't know how you can make your code shorter but I saw this line in your code:

     return f();
    

    From the next calls to f function, it seems that f is a function that takes variable number of arguments.

    You can read in wikipedia that:

    Variadic functions must have at least one named parameter, so, for instance,

    char *wrong(...);

    is not allowed in C.

    Based on that, maybe the return f(); statement is causing you trouble?

提交回复
热议问题