Suppress Compiler warning Function declared never referenced

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

    I find a way to do that globally and it works also in c

    #define SUPPRESS_UNUSED_WARN(var) \
        int _dummy_tmp_##var = ((int)(var) & 0)
    

    then you use it like:

    static int foo(int a, int b)
    {
        // ....
    }
    SUPRESS_UNUSED_WARN(foo);
    
    • it can be used on functions and global variables
    • it should be placed globally in order to work work
    • it can't be used for local variables

提交回复
热议问题