What does "(void)pointer;" mean in c++?
c++, pointers
Solution
It is used to circumvent an unused-variable warning.
If you do use the variable, it is a no-op.
Mostly unused variables are parameters, that are required to fulfil a signature for a callback function, but not needed in your actual implementation.
Cf.
- unused parameter warnings in C code
- GCC manual: `-Wunused-variable` (enabled by `-Wall`, too).
Update:
Just because it was not mentioned otherwise: The type of the variable might be anything. It is not constricted to pointer types.
Problem
There are some c++ code ``` struct data { /* some fields */ }; typedef struct data * pData; int function(pData pointer) { if(pointer == NULL) return ERROR; (void)pointer; /* other work */ } ``` What does "(void)pointer" mean? Just for your information, there are some int/char*/etc, some functions pointers which are used as callback functions in the structure.