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

后端 未结 6 1699
悲&欢浪女
悲&欢浪女 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:42

    With variable-length argument list you must declare the type of the first argument - that's the syntax of the language.

    void f(int k, ...)
    {
        /* do something */
    }
    

    will work just fine. You then have to use va_list, va_start, va_end, etc. inside the function to access individual arguments.

提交回复
热议问题