Wunused-but-set-variable warning treatment

时光毁灭记忆、已成空白 提交于 2019-12-05 06:11:40

You can change your ASSERT macro to:

#if defined (_DEBUG_)
#define ASSERT       assert
#else                           /* _DEBUG_ */
#define ASSERT( exp ) ((void)(exp))
#endif   

If the expression has no sideeffects, then it should still be optimised out, but it should also suppress the warning (if the expression does have side-effects, then you would get different results in debug and non-debug builds, which you don't want either!).

The compiler option to turn off unused variable warnings is -Wno-unused. To get the same effect on a more granular level you can use diagnostic pragmas like this:

int main()
{
  #pragma GCC diagnostic ignored "-Wunused-variable"
  int a;
  #pragma GCC diagnostic pop
  // -Wunused-variable is on again
  return 0;
}

This is, of course, not portable but you can use something similar for VS.

You could surround the variable declaration of status with a #ifdef clause.

#ifdef _DEBUG_
    status_t status
#endif

EDIT: You have to surround the call also:

#ifdef _DEBUG_
    status = pthread_rwlock_unlock(&p_lock->lock);
#else
    pthread_rwlock_unlock(&p_lock->lock);
#endif

or you can switch off the error message.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!