NAME
__USE
—
compile time macro that marks a
variable as being used
SYNOPSIS
#include
<sys/cdefs.h>
void
__USE
(x);
DESCRIPTION
The__USE
macro can be used to omit warnings produced by
certain compilers when variables are being set, but not used in a function.
There are cases where it is simpler to mark a variable as used, as opposed to ifdef out its use:
#ifdef DEBUG_FOO #define DPRINTF(a) printf a #else #define DPRINTF(a) void foo(void) { int var; var = getval(); DPRINTF(("val is %d0, var)); }
In this case, ifdefing the code would make it:
void foo(void) { #ifdef DEBUG_FOO int var; var = getval(); DPRINTF(("val is %d0, var)); #else (void)getval(); #endif }
This is not desirable because it duplicates code. With the
__USE
macro this can be written as:
void foo(void) { int var; var = getval(); #ifdef DEBUG_FOO DPRINTF(("val is %d0, var)); #else __USE(var); #endif }
without producing compiler warnings.
Although it is simple to write:
(void)var;
abstracting this into the macro allows for alternate implementations, as well as changing it to an empty implementation so that the liveness of the variable can be re-evaluated.
IMPLEMENTATION NOTES
__USE
is implemented as:
#define __USE(a) ((void)(a))
SEE ALSO
CAVEATS
__USE
should be used sparingly as it can
cause valid warnings to be hidden.
Use of this macro is non-portable; this is part of the implementation namespace and should only be used in NetBSD code.