我很困惑,为什么我们需要传递无效进入C函数:
I'm confused about why we need to pass void into C functions:
int f(void) { return 0; }与
int f() { return 0; }什么是正确的事情,为什么?
What is the proper thing to do and why?
推荐答案在C, INT F()是一个旧式的声明。它说,˚F需要一个固定的,但数目不详和参数类型(S)。例如,给定 INT F(){返回0; } ,编译器不会抱怨 F(42)或 F(你好,世界)(尽管这种调用的行为是不确定的)。
In C, int f() is an old-style declaration. It says that f expects a fixed but unspecified number and type(s) of arguments. For example, given int f() { return 0; }, the compiler won't complain about f(42), or f("hello, world") (though the behavior of such a call is undefined).
INT F(无效)明确地说,˚F不带任何参数。
int f(void) explicitly says that f takes no arguments.
(C ++有不同的规则。斯特劳斯并不像关心与旧的C code向后兼容)
(C++ has different rules; Stroustrup wasn't as concerned about backward compatibility with old C code.)
更多推荐
使用"无效"用C
发布评论