Suppress Compiler warning Function declared never referenced

前端 未结 9 767
你的背包
你的背包 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:16

    One solution is via function attributes.

    void foo (int, int) __attribute__ ((unused));
    

    This will tell gcc not to issue an unused function warning for the function foo. If you're worried about portability, you can define a macro UNUSED_FUNCTION_ATTRIBUTE that expands to __attribute__ ((unused)) with compilers that support attributes, but expands to nothing otherwise.

提交回复
热议问题