I want to get rid of all implicit-function-declaration warnings in my codebase. But there is a problem because some functions are programmed into the microcontroller ROM at the factory and during linking a linker script provides only the function address. These functions are called by code in the SDK.

During compilation gcc of course emits the warning implicit-function-declaration. How can I get rid of this warning?

To be clear I understand why the warning is there and what does it mean. But in this particular case the developers of SDK guarantee that the code will work with implicit rules (i.e. implicit function takes only ints and returns an int). So this warning is a false positive.

This is gnu-C-99 only, no c++.


  • Guess the argument types, write a prototype in a header and include that?
  • Tell gcc to treat such functions as false positive with some gcc attribute?

4 Answers

Pierce On Best Solutions

You can either create a prototype function in a header, or suppress the warnings with the following:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
/* line where GCC complains about implicit function declaration */
#pragma GCC diagnostic pop
Joshua On

[Completely written due to commends]

You are compiling the vendor SDK with your own code. This is not typically what you want to do.

What you do is you build their SDK files with gcc -c -Wno-implicit-function-declaration and and your own files with gcc -c or possibly gcc -o output all-your-c-files all-their-o-files.

R.. On

C does not require that declarations be prototypes, so you can get rid of the problem (which should be a hard error, not a warning, since implicit declarations are not valid C) by using a non-prototype declaration, which requires only knowing the return type. For example:

int foo();

Since "implicit declarations" were historically treated as returning int, you can simply use int for all of them.

zwol On

Write a small program that generates a header file romfunctions.h from the linker script, with a line like this

int rom_function();

for each symbol defined by the ROM. Run this program from your Makefiles. Change all of the files that use these functions to include romfunctions.h. This way, if the linker script changes, you don't have to update the header file by hand.