Problem with ROS_ASSERT
I am running into the same problem as: https://answers.ros.org/question/2163...
std::string serial_number_str;
if(!config_nh_.getParam("serial_number", serial_number_str))
{
ROS_ERROR("You must specify a serial number");
valid_ = false;
}
else
{
ROS_ASSERT( SerialNumberFromHex(serial_number_str, &serial_number_) );
ROS_INFO_STREAM("serial number="<<serial_number_str<<" ,hex-> "<<serial_number_);
}
The exact same code above works on one machine running Ubuntu 14.04 but failed on a PC running 14.02 (both x64)
However, I found out if I removed ROS_ASSERT, SerialNumberFromHex() function will work. If I use the original code, serial_number_ will never obtain the correct reading from the serial_number_str.
Anyone can explain why this is happening? I know I can get it to work if I modify the code, but I really want to understand why this is happening.
Also I tried to put ROS_INFO() to print out the values, I noticed ROS_ASSERT will not allow me to print out anything:
bool SerialNumberFromHex(const std::string& str, uint64_t* serial_number) {
std::stringstream ss;
ss << std::hex << str;
ROS_INFO_STREAM("ss="<<ss.str());
ss.flush();
ROS_INFO_STREAM("ss="<<ss.str());
ss >> *serial_number;
ROS_INFO_STREAM("ss="<<ss.fail());
return true;
}
This kinda tells me maybe the SerialNumberFromHex() function is never called? So I tried ROS_ASSERT(false) directly, and surprisingly it didn't throw fatal error as expected. So something wrong with ROS_ASSERT command on my machine but without compilation error. Anyone has any clue what's causing the problem (like compiler problem etc)?