From 4a7a46a884bb8a7e71a0a44170b39f99b3667566 Mon Sep 17 00:00:00 2001 From: Jacob Crabill Date: Wed, 16 Jul 2025 14:22:48 -0700 Subject: [PATCH 1/2] Fix compilation errors with Clang Some of these should have been errors with GCC as well, such as attempting to 'extern C' code that is not valid C. The other issue was related to an ambiguous '->operator[]', where GCC correctly took it to mean "dereference the pointer and call operator[] on the dereferenced object", while Clang apparently took it to mean "call operator[] on this pointer". --- .gitignore | 7 +++++++ dynmsg/include/dynmsg/string_utils.hpp | 3 --- dynmsg/include/dynmsg/typesupport.hpp | 2 +- dynmsg/src/message_reading_cpp.cpp | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0bea89 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +tmp/ +build/ +build-*/ + +*.so +*.a +*.tmp diff --git a/dynmsg/include/dynmsg/string_utils.hpp b/dynmsg/include/dynmsg/string_utils.hpp index 6d89fc6..c3b34aa 100644 --- a/dynmsg/include/dynmsg/string_utils.hpp +++ b/dynmsg/include/dynmsg/string_utils.hpp @@ -17,13 +17,10 @@ #include -extern "C" -{ /// Convert a std::string (8-bit characters) to a std::u16string (16-bit characters). std::u16string string_to_u16string(const std::string & input); /// Convert a std::u16string (16-bit characters) to a std::string (8-bit characters). std::string u16string_to_string(const std::u16string & input); -} // extern "C" #endif // DYNMSG__STRING_UTILS_HPP_ diff --git a/dynmsg/include/dynmsg/typesupport.hpp b/dynmsg/include/dynmsg/typesupport.hpp index 3a78f23..286bc81 100644 --- a/dynmsg/include/dynmsg/typesupport.hpp +++ b/dynmsg/include/dynmsg/typesupport.hpp @@ -55,11 +55,11 @@ using MemberInfo = MemberInfo_C; using RosMessage = RosMessage_C; typedef const rosidl_message_type_support_t * (* get_message_ts_func)(); +} // extern "C" // An interface type can be identified by its namespace (i.e. the package that stores it) and its // type name using InterfaceTypeName = std::pair; -} // extern "C" namespace dynmsg { diff --git a/dynmsg/src/message_reading_cpp.cpp b/dynmsg/src/message_reading_cpp.cpp index 072819c..4e6291d 100644 --- a/dynmsg/src/message_reading_cpp.cpp +++ b/dynmsg/src/message_reading_cpp.cpp @@ -396,9 +396,9 @@ dynamic_array_to_yaml_impl_bool( { DYNMSG_DEBUG(std::cout << "DEBUG: dynamic_array_to_yaml_impl_bool" << std::endl); static_cast(member_info); - for (size_t ii = 0; ii < v->size(); ++ii) { - DYNMSG_DEBUG(std::cout << (v->operator[](ii) ? "true" : "false") << ", "); - array_node.push_back(v->operator[](ii)); + for (const bool val : (*v)) { + DYNMSG_DEBUG(std::cout << (val ? "true" : "false") << ", "); + array_node.push_back(val); } DYNMSG_DEBUG(std::cout << std::endl); } From d57ff5d61acd4d70bc9b1d8279ce45d618e1d20a Mon Sep 17 00:00:00 2001 From: Jacob Crabill Date: Sat, 16 Aug 2025 11:53:15 -0700 Subject: [PATCH 2/2] dynmsg_demo: Fix compilation errors --- dynmsg_demo/include/dynmsg_demo/typesupport_utils.hpp | 4 +--- dynmsg_demo/src/cli_tool.cpp | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/dynmsg_demo/include/dynmsg_demo/typesupport_utils.hpp b/dynmsg_demo/include/dynmsg_demo/typesupport_utils.hpp index 715f609..c8bd8a7 100644 --- a/dynmsg_demo/include/dynmsg_demo/typesupport_utils.hpp +++ b/dynmsg_demo/include/dynmsg_demo/typesupport_utils.hpp @@ -23,8 +23,6 @@ #include "rcl/node.h" #include "rcl/types.h" -extern "C" -{ // Get the type name of an existing topic. // The topic must be being published or subscribed to by at least one node. If it is not, then the // topic will not exist and so no type information will be retrievable. @@ -45,5 +43,5 @@ InterfaceTypeName get_topic_type_from_string_type(const std::string & type); // interface type. This pointer is returned. It can be passed to functions such as // rcl_subscription_init(). const TypeSupport * get_type_support(const InterfaceTypeName & interface_type); -} // extern "C" + #endif // DYNMSG_DEMO__TYPESUPPORT_UTILS_HPP_ diff --git a/dynmsg_demo/src/cli_tool.cpp b/dynmsg_demo/src/cli_tool.cpp index 0a0ee76..c210719 100644 --- a/dynmsg_demo/src/cli_tool.cpp +++ b/dynmsg_demo/src/cli_tool.cpp @@ -90,7 +90,7 @@ echo_topic( if (count > 0) { break; } - sleep(0.25); + usleep(250000); } bool taken = false; @@ -364,7 +364,7 @@ main(int argc, char ** argv) return 1; } } catch (const std::runtime_error & e) { - RCUTILS_LOG_ERROR_NAMED("cli-tool", e.what()); + RCUTILS_LOG_ERROR_NAMED("cli-tool", "Runtime error caught while dispatching command"); return 1; }