这个问题是`f(void)`的一个分支,意味着C++ 11或C中没有参数?
有几个人回答了这个问题,并认为在C中,函数原型的意义
void func ()
Run Code Online (Sandbox Code Playgroud)
是func是一个函数返回什么(void),其参数目前是未知的.
此外,他们认为可以制作此声明,然后使用一些参数调用该函数,例如:
func (1, 2, 3);
Run Code Online (Sandbox Code Playgroud)
所以,我做了这个,我做了一个测试,以验证这是否有效,我并不感到惊讶.
这是func.c,其中包含 main()
#include <stdio.h>
extern void func ();
int main (int ac, char ** av)
{
func (1, 2, 3);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这里是包含该函数的func1.c func()
#include <stdio.h>
void func (int a, int b, int c)
{
printf ( "%d, %d, %d\n", a, b, c );
}
Run Code Online (Sandbox Code Playgroud)
这是我的问题
问题1:
当我运行这个程序时,我得到了预期的输出1,2,3.这是一种安全的编写代码的方法; 即可以假设ABI将可靠地确保func()in 的调用main()将三个参数放在正确的位置(寄存器,堆栈,等等)func()以找到它们?
问题2:
如果上面1的答案是安全的话,那么如果用func()C以外的某种语言实现你的答案会改变吗?