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

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

    The ... allows for no arguments, ie: for int printf(const char *format, ...); the statement

    printf("foobar\n");
    

    is valid.

    If you don't mandate at least 1 parameter (which should be used to check for more parameters), there is no way for the function to "know" how it was called.

    All these statements would be valid

    f();
    f(1, 2, 3, 4, 5);
    f("foobar\n");
    f(qsort);
    

提交回复
热议问题