Search code examples
cgccmicrocontroller

GCC how to stop false positive warning implicit-function-declaration for functions in ROM?


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++.

Ideas:

  • 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?

Solution

  • 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