ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

After some digging, it would appear that the underlying type of std_msgs::Bool.data is uint8_t (source).

This is why something like the following fails to compile:

std_msgs::Bool my_bool;
bool & ref_my_bool = my_bool.data;

Perhaps a workaround is to use uint8_t type explicitly:

std_msgs::Bool my_bool;
uint8_t & ref_my_bool = my_bool.data;

Or in your example:

void test2(uint8_t &test)
{    
    return;
}
void test(std_msgs::Bool &bool_test)
{
    //TEST 1
    bool a_bool;
    test2(a_bool); //Ok

    //TEST 2
    a_bool = bool_test.data;
    test2(a_bool); //Ok

   //TEST 3
    bool_test.data = a_bool;
    test2(bool_test.data); //Not okay
    return;
}

After some digging, it would appear that the underlying type of std_msgs::Bool.data is uint8_t (source).

This is why something like the following fails to compile:

std_msgs::Bool my_bool;
bool & ref_my_bool = my_bool.data;

Perhaps a workaround is to use uint8_t type explicitly:

std_msgs::Bool my_bool;
uint8_t & ref_my_bool = my_bool.data;

Or in your example:

void test2(uint8_t &test)
{    
    return;
}
void test(std_msgs::Bool &bool_test)
{
    //TEST 1
    bool a_bool;
    test2(a_bool); //Ok

    //TEST 2
    a_bool = bool_test.data;
    test2(a_bool); //Ok

   //TEST 3
    bool_test.data = a_bool;
    test2(bool_test.data); //Not okay
// Ok
    return;
}

After some digging, it would appear that the underlying type of std_msgs::Bool.data is uint8_t (source).

This is why something like the following fails to compile:

std_msgs::Bool my_bool;
bool & ref_my_bool = my_bool.data;

Perhaps a workaround is to use uint8_t type explicitly:

std_msgs::Bool my_bool;
uint8_t & ref_my_bool = my_bool.data;

Or in your example:

void test2(uint8_t &test)
{    
    return;
}
void test(std_msgs::Bool &bool_test)
{
    //TEST 1
    bool a_bool;
    test2(a_bool); //Ok

    //TEST 2
    a_bool = bool_test.data;
    test2(a_bool); //Ok

   //TEST 3
    bool_test.data = a_bool;
    test2(bool_test.data); // Ok
//Ok
    return;
}

After some digging, it would appear that the underlying type of std_msgs::Bool.data is uint8_t (source).

This is why something like the following fails to compile:

std_msgs::Bool my_bool;
bool & ref_my_bool = my_bool.data;

Perhaps a workaround is to use uint8_t type explicitly:

std_msgs::Bool my_bool;
uint8_t & ref_my_bool = my_bool.data;

Or in your example:passing by reference to a function:

#include <stdint.h>
#include <std_msgs/Bool.h>

void test2(uint8_t data_by_ref(uint8_t &test)
{    
{
    return;
}
void test(std_msgs::Bool std_bool_by_ref(std_msgs::Bool &bool_test)
{
    //TEST 1
data_by_ref(bool_test.data);
}

int main(void)
{
 std_msgs::Bool my_bool = std_msgs::Bool();
 bool a_bool;
std_bool_by_ref(my_bool);
   test2(a_bool); //Ok

    //TEST 2
    a_bool = bool_test.data;
    test2(a_bool); //Ok

   //TEST 3
    bool_test.data = a_bool;
    test2(bool_test.data); //Ok
    return;
return 0;
}