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 want
-Wimplicit-function-declarationwarning.Personally, I prefer compiling my code with
-Wall -Wextra.