Suppress Compiler warning Function declared never referenced

前端 未结 9 770
你的背包
你的背包 2020-12-30 01:51

So i have some code like this:

void foo (int, int);

void bar ( )
{
    //Do Stuff

   #if (IMPORTANT == 1)
       foo (1, 2);
   #endif

}

9条回答
  •  感动是毒
    2020-12-30 02:19

    I'm fairly sure the relevant warning option is this one:

    -Wunused-function
    Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall.

    So the warning should only be given for a static function, interesting. Makes sense. If a function is static it can only be used within the current file, so its definition must also be in this file.

    And declaring it static inline avoids the warning, without resorting to ugly macros or compiler-specific pragmas or attributes.

提交回复
热议问题