Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

statement with only a variable name

Tags:

c++

variables

I just saw a guy did this today when I was studying his code fragment:

void doSomething(int param) {
    // stuffs
    param; // <-- what does this statement do?
    // stuffs
}

I tried looking for it on the internet and asked most of my friends about it but this one looks alien to them too. So guys, what does that statement do really?

like image 665
Ngoc Avatar asked Jan 29 '26 02:01

Ngoc


1 Answers

It may serve to remove a warning about unused parameters. But logically it does nothing. There are better ways to remove the warning about an unused parameter. Using a macro:

UNREFERENCED_PARAMETER( param );

Or by removing the name of the parameter from the function:

void doSomething(int /*param*/) { ... 

I prefer the latter, because it means that param is definitely not used. I've seen instances of UNREFERENCED_PARAMETER being specified, then later in the code the parameter is actually used.

like image 85
Steve Avatar answered Jan 30 '26 15:01

Steve



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!