Subject: __unused function args
To: None <tech-toolchain@NetBSD.org>
From: Valeriy E. Ushakov <uwe@ptc.spbu.ru>
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
effect".
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.
Thoughts?
PS: Inspired by the 9fans thread at
http://lists.cse.psu.edu/archives/9fans/2005-November/thread.html#43681
SY, Uwe
--
uwe@ptc.spbu.ru | Zu Grunde kommen
http://snark.ptc.spbu.ru/~uwe/ | Ist zu Grunde gehen