__USE(3) | Library Functions Manual | __USE(3) |
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.
#define __USE(a) ((void)(a))
Use of this macro is non-portable; this is part of the implementation namespace and should only be used in NetBSD code.
October 17, 2013 | NetBSD 7.2 |