<分区>
我有这样的功能:
//in header
int Foo()
// in source file
int Foo()
{
return 1;
}
在我访问的其他源文件中,功能如下:
int aninteger;
result = Foo(aninteger);
该代码正在编译,没有给出任何警告。知道为什么吗? 如何设置 visual studio 以警告我函数调用中的参数不匹配?
<分区>
我有这样的功能:
//in header
int Foo()
// in source file
int Foo()
{
return 1;
}
在我访问的其他源文件中,功能如下:
int aninteger;
result = Foo(aninteger);
该代码正在编译,没有给出任何警告。知道为什么吗? 如何设置 visual studio 以警告我函数调用中的参数不匹配?
最佳答案
发生这种情况是因为,用空参数列表声明的函数表示编译器不知道要传递或处理的实际参数。因此,一般来说,编译器没有义务生成任何诊断信息。
相反,使用 int Foo(void)
明确提及缺少参数。
在 gcc 中,您可以使用 -Wstrict-prototypes
但是,通知编译器警告您前一个不匹配的选项。
关于c - 为什么我在将参数传递给不应接受任何传入参数的函数时没有收到警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39413241/