Why is the comma optional in C++ variadic function declarations?

前端 未结 1 2002
离开以前
离开以前 2021-01-05 03:32

Is there a difference in these two declarations?

int foo( int a, ... );

and

int foo( int a ... );

If ther

相关标签:
1条回答
  • 2021-01-05 04:31

    This is speculation, but in C++ in can make sense to have a function with no other parameters, e.g. void f(...) whereas in C a function like this has no use (that I know of) so ... must follow some other parameter and hence, a comma.

    From a grammar point of view, it's simpler to simply allow void f( int a ... ) and give it the obvious meaning than it is to disallow it and it's not going to cause much of a burden on compiler writers or any confusion for programmers.

    (I originally thought it might be something to do with making the grammar for parameter packs more regular but I discovered that it was explicitly allowed in C++03 in any case.)

    0 讨论(0)
提交回复
热议问题