__USE(3) - NetBSD Manual Pages

__USE(3)                NetBSD Library Functions Manual               __USE(3)


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 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.
IMPLEMENTATION NOTES
__USE is implemented as: #define __USE(a) ((void)(a))
SEE ALSO
cc(1), cdefs(3)
CAVEATS
__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 7.0.2 October 17, 2013 NetBSD 7.0.2

Powered by man-cgi (2024-08-26). Maintained for NetBSD by Kimmo Suominen. Based on man-cgi by Panagiotis Christias.