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?
1 : consisting of or existing in two corresponding or identical parts or examples duplicate invoices. 2 : being the same as another duplicate copies. duplicate.
always used before a noun. : exactly the same as something else. I began receiving duplicate copies of the magazine every month.
to make an exact copy of something: The documents had been duplicated. Parenthood is an experience nothing else can duplicate. SMART Vocabulary: related words and phrases. Copying and copies.
The verb duplicate is pronounced differently, with a long a sound, and it means to make a copy of or to multiply times two. The Latin root, duplicatus, means "to double." Definitions of duplicate. a copy that corresponds to an original exactly. “he made a duplicate for the files”
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)filename
is how you might prevent both warnings.
It's preventing a warning about an unused parameter, nothing more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With