ros-drivers / rosserial

A ROS client library for small, embedded devices, such as Arduino. See: http://wiki.ros.org/rosserial
508 stars 527 forks source link

fixed nh.getParam template with gcc-arm-none-eabi #587

Open SubaruArai opened 2 years ago

SubaruArai commented 2 years ago

with the following code:

template <typename T>
static inline T get_single_param_(const char *param_name, T default_value)
{
    std::array<T, 1> buf;
    if (nh.getParam(param_name, buf.data())) {
        return buf[0];
    } else {
        return default_value;
    }
}

Under rp2040 (arm-none-eabi-gcc, 32bit), if T is "int", gcc will convert the int to "short int" thus failing compilation. Using "int32_t" for T didn't help, and fundamentally it's a problem of "int" not being really cross-platform. Changing the "int" in rosserial_client.h to "int32_t" fixed the issue.

Ultimately, all "int" in the codebase should be "int32_t" including message_generation, but that would be a breaking change.

Even this change might be breaking for some codes.