UNUSED macro warning
So I found this macro on SO:
#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 UNUSED(x) (void)(x)
is 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.
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.
The answer you linked, is also linking to where this solution is from: here
The actual source of this solution is saying that it still does produce warnings and is giving proper solutions.
上一篇: Java是否支持默认参数值?
下一篇: UNUSED宏警告