Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please Explain The Meaning of Following Cast [duplicate]

Tags:

c

casting

void

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?

like image 970
themaestro Avatar asked Nov 18 '11 22:11

themaestro


People also ask

What do you mean by duplicate?

1 : consisting of or existing in two corresponding or identical parts or examples duplicate invoices. 2 : being the same as another duplicate copies. duplicate.

What is duplicate example?

always used before a noun. : exactly the same as something else. I began receiving duplicate copies of the magazine every month.

What does duplicate mean in a sentence?

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.

What means creating a duplicate?

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”


2 Answers

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.

like image 128
Platinum Azure Avatar answered Sep 17 '22 09:09

Platinum Azure


It's preventing a warning about an unused parameter, nothing more.

like image 44
Michael Dorgan Avatar answered Sep 19 '22 09:09

Michael Dorgan