(void)foo or __unused foo ?

Luigi Rizzo rizzo at iet.unipi.it
Fri Jul 27 09:18:26 UTC 2012


In writing cross platform code I often have to deal with function
arguments or variables that are not used on certain platforms.
In FreeBSD:sys/cdefs.h we have

	#define __unused        __attribute__((__unused__))

and in the kernel we tend to annotate with "__unused" such arguments

	int f(type foo __unused)

However on linux __unused is not a standard macro, and is often
used as a variable or field name in standard headers, so introducing
our __unused macro breaks compilation there.

The alternative way to avoid an 'unused' warning from the compiler
is an empty statement

	(void)foo;

that the compiler hopefully optimizes away.

Any disadvantage or objection to selectively use this form
in our kernel code for parts that need to work on multiple
platforms ?

	cheers
	luigi


More information about the freebsd-current mailing list