__USE(3) - NetBSD Manual Pages

Command: Section: Arch: Collection:  
__USE(3)                NetBSD Library Functions Manual               __USE(3)

__USE -- compile time macro that marks a variable as being used
#include <sys/cdefs.h> void __USE(x);
The __USE macro can be used to omit warnings produced by certain compil- ers 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.
__USE is implemented as: #define __USE(a) ((void)(a))
cc(1), cdefs(3)
__USE should be used sparingly as it can cause valid warnings to be hid- den. Use of this macro is non-portable; this is part of the implementation namespace and should only be used in NetBSD code. NetBSD 9.99 October 17, 2013 NetBSD 9.99
Powered by man-cgi (2021-03-02). Maintained for NetBSD by Kimmo Suominen. Based on man-cgi by Panagiotis Christias.