(void)foo or __unused foo ?
Tim Kientzle
tim at kientzle.com
Sat Jul 28 06:41:17 UTC 2012
On Jul 27, 2012, at 2:38 AM, Luigi Rizzo wrote:
>
> The alternative way to avoid an 'unused' warning from the compiler
> is an empty statement
>
> (void)foo;
>
> that the compiler hopefully optimizes away.
I learned the void-cast convention many years ago.
I used it throughout the libarchive code and have yet to
run into any problems. I always use it in exactly this form
(with the exact comment here) so that I can easily search
on it:
int foo(int a) {
(void) a; /* UNUSED */
…
}
I agree with PHK that it would be nice to express this
intent in a way that static checkers could verify. I also
agree that having static checkers interpret comments is Evil.
But I have yet to see any alternative that was as
straightforward and widely-supported as this one.
Every other viable alternative seems to require tangled
clumps of macros.
Tim
More information about the freebsd-current
mailing list