Consider this code:
int function()
{
int a = 1 ;
int b = helper(&a);
return b ;
}
int main()
{
function();
return 0 ;
}
This code snippet compiles to object code without problem using gcc, despite the fact that the function called 'helper' has not been declared. I know that the linker should catch this but I've seen obscure bugs which resolved once the correct headers (containing the function declarations) were included, despite the linker and compiler not generating any errors.
There are a number of gcc warnings which seem to be related but do not actually achieve what I want: -Wmissing-prototypes, -Wmissing-declarations and -Wstrict-prototypes. Unfortunately, these warnings are limited to missing prototypes when global functions are defined, I'm interested in warnings about missing prototypes when global functions are referenced.
Can anyone suggest alternatives?, thanks.
You can request many specific warnings with options beginning with ' -W ', for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning ' -Wno- ' to turn off warnings; for example, -Wno-implicit .
You can use the -Werror compiler flag to turn all or some warnings into errors.
gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.
Please point me to a source or explain in brief, What does the Flag -I does? It instructs the compiler to add the argument of the flag -I to the include files search path. In Unix/Linux world you typically start from man gcc when need to find about comand line flags of gcc .
You want -Wimplicit-function-declaration
warning.
Personally, I prefer compiling my code with -Wall -Wextra
.
Use -Wl,--no-undefined
to ensure a forced undefined function
error.
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