Hi there
Welcome to my blog
读完f() vs f(void) in C vs C++做的笔记. C中f()与f(void)区别 f()表示函数形参列表是未知的, 编译器不会帮你做检查. 可以看到gcc编译下面程序, 没有警告. $ cat test.c #include <stdio.h> void foo() { printf("foo\n"); } int main(void) { foo(1, 2, 3); } $ gcc ./test.c -std=c11 -O2 -Wall -Wextra -Werror -o test $ ./test foo f(void)才真正表示函数形参列表为空. $ cat test.c #include <stdio.h> void foo(void) { printf("foo\n"); } int main(void) { foo(1, 2, 3); } $ gcc ./test.c -std=c11 -O2 -Wall -Wextra -Werror -o test ./test.c: In function ‘main’: ./test.c:8:3: error: too many arguments to function ‘foo’ 8 | foo(1, 2, 3); | ^~~ ./test.c:3:6: note: declared here 3 | void foo(void) { | ^~~ 另外X86-64生成的机器指令也会受到影响. 可以看到下面的程序能够正常执行, faz与baz分别调用foo以及bar. ...