问题描述
我最近不得不输入一个小的C测试程序,并在这个过程中,我意外地使用作出的主要功能拼写错误 vooid
而不是无效
。
然而它仍然工作。
降低下来到其最小完整版,我结束了:
INT主(vooid){
返回42;
}
这确实的确实的编译(的gcc -o -Wall MYPROG myprog.c中
),并在运行时,它会返回42。
究竟这是怎么有效的code?
下面是一个转录剪切和从我的庆典
粘贴外壳展现我在做什么:
PAX $猫qq.c
诠释主要(vooid){
返回42;
}PAX $ RM QQ; GCC -Wall -o QQ qq.c; ./qqPAX $回声$?
42
它仅仅使用了旧式函数声明语法;你是隐式声明称为 INT
参数 vooid
。
I recently had to type in a small C test program and, in the process, I made a spelling mistake in the main function by accidentally using vooid
instead of void
.
And yet it still worked.
Reducing it down to its smallest complete version, I ended up with:
int main (vooid) {
return 42;
}
This does indeed compile (gcc -Wall -o myprog myprog.c
) and, when run, it returns 42.
How exactly is this valid code?
Here's a transcript cut and pasted from my bash
shell to show what I'm doing:
pax$ cat qq.c
int main (vooid) {
return 42;
}
pax$ rm qq ; gcc -Wall -o qq qq.c ; ./qq
pax$ echo $?
42
It's simply using the "old-style" function-declaration syntax; you're implicitly declaring an int
parameter called vooid
.
这篇关于" INT主(vooid)QUOT ;?这是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!