#define
UNUSED(x) (void)(sizeof((x),
0))
and this (still)
produces the following warning:
main.c:11:36:
warning: left-hand operand of comma expression has no effect [-Wunused-value]
#define UNUSED(x) (void)(sizeof((x),
0))
Whereas
the simpler version, a normal void
cast: #define
is
UNUSED(x) (void)(x)
warning-free.
What could be the reason behind
it? In general warnings are a sign of high-risk situations. Is here the given warning
really useful?
I am interested in
C-explanation.
class="normal">Answer
This macro
seems inappropriate for your compiler at the current warning
level.
You could use this simpler
version:
#define
UNUSED(x)
(void)(sizeof(x))
x
will not be evaluated either but is used so the compiler should not
complain about x
being unused, not about the left hand side of
the ,
operator being unused in the
expression.
No comments:
Post a Comment