NL.25: Don't use void as an argument type
NL.25:不要将void用作参数类型
Reason
It's verbose and only needed where C compatibility matters.
它很冗长,只有在C兼容性很重要的情况下才需要这么做。
Example(示例)
代码语言:javascript复制void f(void); // bad
void g(); // better
Note(注意)
Even Dennis Ritchie deemed void f(void) an abomination. You can make an argument for that abomination in C when function prototypes were rare so that banning:
哪怕丹尼斯·里奇也认为void f(void)是可憎的。当函数原型很少见时,您可以为C中的可憎性辩护,因此禁止:
代码语言:javascript复制int f();
f(1, 2, "weird but valid C89"); // hope that f() is defined int f(a, b, c) char* c; { /* ... */ }
would have caused major problems, but not in the 21st century and in C .
会造成重大问题,但不会在21世纪和C 中引起。
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#nl25-dont-use-void-as-an-argument-type