Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Jul 2012 11:38:24 +0200
From:      Luigi Rizzo <rizzo@iet.unipi.it>
To:        current@freebsd.org
Subject:   (void)foo or __unused foo ?
Message-ID:  <20120727093824.GB56662@onelab2.iet.unipi.it>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120727093824.GB56662>