只有一个变量名的语句 [英] statement with only a variable name
问题描述
我今天刚刚在研究他的代码片段时看到一个人这样做了:
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?
推荐答案
它可能有助于删除有关未使用参数的警告.但从逻辑上讲,它什么都不做.有更好的方法可以消除有关未使用参数的警告.使用宏:
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*/) { ...
我更喜欢后者,因为这意味着 param
绝对不会被使用.我已经看到指定了 UNREFERENCED_PARAMETER
的实例,然后在代码中实际使用了参数.
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.
这篇关于只有一个变量名的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!