Why is void f(…) not allowed in C?

后端 未结 6 1652
悲&欢浪女
悲&欢浪女 2021-01-05 15:31

Why doesn\'t C allow a function with variable length argument list such as:

void f(...)
{
    // do something...
}
6条回答
  •  天涯浪人
    2021-01-05 15:38

    C does allow for variable length arguments, but you need to use va_list, va_start, va_end, etc. for it. How do you think printf and friends are implemented? That said, I would recommend against it. You can usually accomplish a similar thing more cleanly using an array or struct for the parameters.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题