Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reason behind using (void)someInt; in code

Tags:

c++

I am reading some code of a library I am using, and I found that in a function this was used:

void someFunction(Foo& a, int index, int partId)
{
    (void) partId;
    (void) index;
    // more code
}

Anyone knows why? Thanks.

like image 614
Pacha Avatar asked Jan 10 '14 17:01

Pacha


1 Answers

To avoid a compiler warning/error indicating that the variable was unused in the function body. It's a style choice, the other way to achieve the same effect would be to leave the variable un-named:

void someFunction(Foo& a, int /*index*/, int /*partId*/)
like image 55
kfsone Avatar answered Oct 12 '22 10:10

kfsone