ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Problem with ROS_ASSERT

asked 2017-09-13 00:36:04 -0500

johnyang gravatar image

updated 2017-09-13 01:07:04 -0500

I am running into the same problem as:

std::string serial_number_str;
if(!config_nh_.getParam("serial_number", serial_number_str))
    ROS_ERROR("You must specify a serial number");
    valid_ = false;
    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;
    ss >> *serial_number;
    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)?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-05-20 02:15:25 -0500

tfoote gravatar image

You should check what build flags you're running. If you have turned on optimizations and are building for release asserts will be compiled out for faster operations. If you need the code inside to run in regular operations they should not be done inside an assert.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-09-13 00:36:04 -0500

Seen: 511 times

Last updated: May 20 '19