Based on the name, it looks like a way to get rid of the "unused variable" warning. The intended use is probably something like this:
int function(int i) { USE_VAL(i) return 42; }
Without this, you can get a compiler warning that the i parameter is not used inside the function.
However, this is a rather dangerous way to get around this, because it injects Undefined Behavior into the code (pointer arithmetic outside the actual Undefined array by standard). You can add 1 to the address of the object, but do not subtract 1. Of course, instead of + 1 instead of - 1 compiler could warn that the condition is always true. The optimizer may delete the entire if and the code will remain valid, but the optimizers will improve when using the “undefined behavior cannot happen”, which can really spoil the code completely unexpectedly.
Not to mention that operator& can be overloaded for the corresponding type, which could potentially lead to undesirable side effects.
There are more efficient ways to implement functions such as casting in void :
#define USE_VAL(X) static_cast<void>(X)
However, my personal preference is to comment on the parameter name in the function definition, for example:
int function(int ) { return 42; }
The advantage of this is that it actually prevents accidental use of the parameter after passing it to the macro.
source share