Avoiding unused variables warnings when using assert() in a Release build

We use a macro to specifically indicate when something is unused:

#define _unused(x) ((void)(x))

Then in your example, you’d have:

int Result = Func();
assert( Result == 1 );
_unused( Result ); // make production build happy

That way (a) the production build succeeds, and (b) it is obvious in the code that the variable is unused by design, not that it’s just been forgotten about. This is especially helpful when parameters to a function are not used.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)