Re: Need your experience: is "(void)param;" to avoid unused variable
warnings well known for you?
On 4/2/2012 10:01 AM, Qi wrote:
On 2012-4-2 21:49, Victor Bazarov wrote:
I've seen that trick usually used in (a) a larger function than just one
empty line and one line of comment, and (b) in presence of some reason
to keep the argument name, like alternative configurations
(Debug/Release for instance):
I don't understand (a).
Can you give some example code?
*You* gave the example code. In your code the function had effectively
an empty body. In that case there is no need to have "ignore"
templates, "UNUSED_PARAMETER" macros, or any other BS. Just drop the
argument altogether.
I am talking any reasonable function that actually is supposed to do
something. The "code example" is below.
void someFunction(int argumentUsedOnlyInDebug)
{
... // some code
#ifdef NDEBUG
(void)argumentUsedOnlyInDebug;
#else
... // some code that uses argumentUsedOnlyInDebug
#endif
... // more code
}
Any suggestions for a better alternative?
I think one more readable way is using some marco?
#define UNUSED_ARG(arg) (void)arg
UNUSED_ARG(argumentUsedOnlyInDebug);
It's less confusing than
(void)argumentUsedOnlyInDebug;
<shrug> Same difference.
V
--
I do not respond to top-posted replies, please don't ask