I have a function like:
//in header
int Foo()
// in source file
int Foo()
{
return 1;
}
In one the other source files I access function as:
int aninteger;
result = Foo(aninteger);
That code is compiling without giving any warning. Any idea why? How can I set visual studio to warn me about argument mismatches in calls to functions?
This happens because, a function declared with an empty parameter list signifies that the compiler has no idea about the actual arguments to be passed or handled. So, in general, the compiler is under no obligation to produce any diagnostic.
Instead, use int Foo(void)
to explicitly mention the absence of parameters.
In gcc, you can use -Wstrict-prototypes
option to inform the compiler to warn you abut the former mismatch, however.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With