I have the following code, and while compiling it with gcc-4.6 I get warning:
warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
#if defined (_DEBUG_)
#define ASSERT assert
#else /* _DEBUG_ */
#define ASSERT( __exp__ )
#endif
static inline void cl_plock(cl_plock_t * const p_lock)
{
status_t status;
ASSERT(p_lock);
ASSERT(p_lock->state == INITIALIZED);
status = pthread_rwlock_unlock(&p_lock->lock);
ASSERT(status == 0);
}
When _DEBUG_ flag isn't set I get the warning. Any ideas how can I workaround this warning?
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: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.EDIT: You have to surround the call also:
or you can switch off the error message.
You can change your
ASSERT
macro to: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!).