Silence of unused variable warning
It would be nice to silence the warnings caused by unused variables. There are several ways to do it:
- do not name the unused argument (not preferable),
- use [[maybe_unused]] (since C++17) in function definition,
- typecast the unused variable (void) var. This approach is used in Qt. For example consider the following function:
static std::string name( CudaStatusType error_code )
{
#ifdef HAVE_CUDA
return cudaGetErrorName( error_code );
#else
(void) error_code;
throw CudaSupportMissing();
#endif
}
The approach in Qt discussed here is the following:
#define UNUSED(var) (void) var
Then, the warning can be silenced by UNUSED(error_code);
.