The code I'm working on has a function which has a double pointer of type void, in the function pointer the double pointer is typecasted to void, and the pointer is not used anywhere else. I cant find any where why this is done. someone please shed some light.
static void kbd_callback(const char *name, int name_len,
const char *instruction, int instruction_len,
int num_prompts,
const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts,
LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses,
void **abstract /* <-- This */)
{
int i;
size_t n;
char buf[1024];
(void)abstract; // <---- and this
...
}
The type of the callback is probably part of the API of a LIBSSH2 library. The library passes every parameter to the callback that it expects the callback will need. Whatever that parameter is, this particular callback doesn't need it. The programmer has four choices:
He can leave out the name of the parameter in the prototype, replacing void **abstract
with void **
. This makes it so that someone trying to understand his code has to look at the LIBSSH2 API to understand what the last parameter is.
He can just not use the parameter. But this will get him a warning from his compiler.
He can use the parameter in a way that has no consequence to hide the warning.
He could comment out the parameter name, like this: void ** /*abstract*/
.
This programmer choose option 3.
Personally, I tend to prefer option 4 for this case. I'd also prefer to see something like this:
#define OK_UNUSED(a) if (false && (a)); else (void) 0
...
OK_UNUSED(abstract);
This makes it very clear that it's okay that the parameter is unused.