I've seen this C++ function in a ROS kobuki node ( kobuki-auto-docking ). I wonder if the while is dead code ? Or if it can be called for a misterious reason sometimes ?
void AutoDockingROS::spin()
{
return;
while(!shutdown_requested_){;}
}
Thanks for your helps,
In C++, nothing after return
is executed.
But, you should always respect the code you see in front of you:
If the preprocessor #define
s return
to something else for a particularly odd build configuration then the code could run.
Someone might be porting the code blindly to Java. In Java, code within a finally
block does run after a return
.
It's possible the developer retained the line to test the syntactic validity of !shutdown_requested_
All unlikely scenarios (I have seen the first one in production by the way) but worth checking if you're going to undertake a large refactoring effort.
return
语句后的所有内容永远不会被执行。
It is equivalent to this:
void AutoDockingROS::spin()
{
return;
// while(!shutdown_requested_){;}
}
Effectively, the programmer wanted to leave some code there, perhaps as a reminder. It is never executed.
返回后没有人可以调用代码......好吧也许只有查克诺里斯可以......
Nothing can be executed after the return
statement until its within a condition. Put the code above the return
statement.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.