Subject: __unused function args
To: None <>
From: Valeriy E. Ushakov <>
List: tech-toolchain
Date: 10/13/2006 02:48:45
__unused function args have some problems with macros and cpp
conditionals, b/c we don't know if given macro actualy uses the
argument (e.g. on other platforms), and different #if branches may use
different set of arguments.

We need something like plan9 USED(x), so that macros and #if branches
can "consume" args.

One option is

#define USED(x) do { (void)&x; } while (0)

But that needs a lint stub to avoid " warning: expression has null

Another option, that is lint-happy as-is, is

#define USED(x) do { if (&x) {} } while (/* CONSTCOND */ 0)

The nit-pick is that & doesn't work with arguments declared
"register", but "register" args are so 1980s, that I think we don't
care :).  The benefit of & is that it takes care about struct args.

Ideally, USED should aslo ensure that its argument is a plain
variable, or at least make sure it doesn't evaluate its argument.

#define USED(x) do { if (sizeof(x)) {} } while (0)

seems to keep gcc happy w.r.t. x being "used" by sizeof(), but lint
doesn't seem to believe in this kind of usage.


PS: Inspired by the 9fans thread at

SY, Uwe
--                         |       Zu Grunde kommen          |       Ist zu Grunde gehen