(void)foo or __unused foo ?

From: Luigi Rizzo <rizzo_at_iet.unipi.it>
Date: Fri, 27 Jul 2012 11:38:24 +0200
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
Received on Fri Jul 27 2012 - 07:18:26 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:29 UTC