Of the three, the last option, (void)x;
is preferable in most cases.
The first option, leaving the parameter unnamed, is acceptable, but often it is useful for the parameter to have a name for debugging purposes (e.g., even if you aren't using the parameter in the function, you might be interested in its value when debugging). There are cases where this option is fine, though, e.g. when doing tag dispatching.
The second option, x;
may cause other warnings. Visual C++ will issue warning C4555 for this code:
warning C4555: expression has no effect; expected expression with side-effect
By casting x
to void
via (void)x;
, this warning is suppressed. (Note that this warning is off by default; this warning must be expressly enabled via #pragma
or command-line option.)