Statements after return statement in C ++ - functions
I've seen this C ++ feature in ROS kobuki node ( kobuki-auto-docking ). I wonder if this is dead code? Or if it can be caused for different reasons sometimes?
void AutoDockingROS::spin()
{
return;
while(!shutdown_requested_){;}
}
Thanks for the help,
source to share
In C ++, nothing is executed after return
.
But you should always respect the code you see in front of you:
-
If the preprocessor is
#define
return
for something else for a particularly complex build configuration, then the code might work. -
Someone can blindly port the code to Java. In Java, the code inside the block is
finally
run afterreturn
. -
The developer may have saved the string for syntactic validation
!shutdown_requested_
All unlikely scenarios (by the way, I saw the first one in production), but it's worth checking to see if you will be putting in a lot of refactoring efforts.
source to share