是更好地用C无效参数"无效美孚(无效)QUOT;还是不"无效美孚()"? [英] Is it better to use C void arguments "void foo(void)" or not "void foo()"?
问题描述
什么是更好的:无效美孚()
或无效美孚(无效)
?
随着空它看起来丑陋的和不一致的,但我已经告诉这是好的。这是真的吗?
编辑:我知道有些老的编译器做奇怪的事情,但如果我只用GCC,为无效美孚()
好吧?请问富(巴);
则可以接受
无效美孚(无效);
这是说,在C没有参数的正确的方法,而且它也适用于C ++。
不过:</ P>
无效美孚();
意味着C和C ++不同的事情!在C语言中的意思是可以采取任何数量的未知类型参数,并在C ++中它的意思一样富(无效)
。
变量参数列表功能,本质上是未类型安全,应尽量避免使用。
What is better: void foo()
or void foo(void)
?
With void it looks ugly and inconsistent, but I've been told that it is good. Is this true?
Edit: I know some old compilers do weird things, but if I'm using just GCC, is void foo()
Ok? Will foo(bar);
then be accepted?
void foo(void);
That is the correct way to say "no parameters" in C, and it also works in C++.
But:
void foo();
Means different things in C and C++! In C it means "could take any number of parameters of unknown types", and in C++ it means the same as foo(void)
.
Variable argument list functions are inherently un-typesafe and should be avoided where possible.
这篇关于是更好地用C无效参数&QUOT;无效美孚(无效)QUOT;还是不&QUOT;无效美孚()&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!