This is NOT a question on how to resolve the "implicit declaration of function" warnings that appear in C programs, that has been answered many times already.
I understand that this is a compiler warning, what I'm wondering is why is this a warning rather than an error? If the compiler cannot see the function, what happens when the function is called at runtime? Does the linker ultimately resolve this issue? Or are we to assume that the behaviour of calling a function that produced such warning is unknown?
implicit declaration of function means that you are trying to use a function that has not been declared. In our example above, StartBenchmark is the function that is implicitly declared.
You can declare a function as an explicitly defaulted function only if the function is a special member function and has no default arguments. For example: class B { public: int func() = default; // Error, func is not a special member function.
Werror is a GCC argument, and you cannot remove it directly via ./configure. Otherwise, an option like --disable-error would show up in the help text.
why is this a warning rather than an error?
Because there are a lot of legacy code thet is written in such way. Compiler error will break it.
If the compiler cannot see the function, what happens when the function is called at runtime? Does the linker ultimately resolve this issue?
Let's look the example:
int main()
{
foo();
return 0;
}
When working the compiler generates its own function signature like int foo(...)
and will use it. By the way it can lead to very curious errors. So the object file will contain the call of this function and it is ok. When you will try to link it you will get an error: undefined reference to `foo'. But if you have another module with foo
definition, the linker will find it by name and link it.
Or are we to assume that the behaviour of calling a function that produced such warning is unknown?
As I said it can lead to some curious errors. Imagine that you have code like int i = foo()
and foo
is without signature. And in another module you have the following: int * foo(){...}
. When building application in 64 bit mode you will put to i
only 32 bit of a 64 bit pointer. So you may say in fact the behaviour of your program may be unknown.
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