ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
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;
}
2 | No.2 Revision |
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;
}
3 | No.3 Revision |
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;
}
4 | No.4 Revision |
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;
}