Possible Duplicate:
Weird use of void
I was reading C code and came across the following. Can somebody please explain what this does?
static int do_spawn(const char *filename)
{
(void)filename;
// todo: fill this in
return -1;
}
Specifically, what is the (void) filename doing?
Compilers sometimes complain about unused parameters; the
(void)“cast” is simply a way to use the variable in a void, non-side-effect context so that the compiler won’t complain about it being “unused”.EDIT: As rodrigo points out below, the compiler warning can be suppressed without the
(void)prefix, but then another warning (about the expression having no effect) may appear instead. So(void)filenameis how you might prevent both warnings.