Suppress Compiler warning Function declared never referenced

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

    ...then I started to wonder if there was a different way to suppress that warning on that function.

    There might be compiler option(s) to suppress this warning. However, one trick is this:

    (void)foo; //cast it to void.
    

    It should suppress this warning.

    You could write a macro:

    #define SUPPRESS_WARNING(a) (void)a
    
    void foo(int thisIsAlsoAnUnsedParameter, int usedParameter)
    {
       SUPPRESS_WARNING(foo); //better do this inside the definition itself :D
    
       SUPPRESS_WARNING(thisIsAlsoAnUnsedParameter);
    }
    

    As you can see, the definition of foo itself suppresses the warning.

提交回复
热议问题