[ros-users] [Discourse.ros.org] [General] So many trailing underscores

Dirk Thomas ros.discourse at gmail.com
Fri Mar 17 16:35:42 UTC 2017

The trailing underscore on struct names ensures that the full name is guaranteed to be a valid C++ struct name. Without the underscore depending on how the use names the message it might not be. E.g. a user might use a message which collides with a keyword. The same holds true for the fields.

It would certainly be possible to state in the docs "don't use any C++ keywords as message/field names". But that would not be sufficient for all generated code. It would need to be "don't use any keywords from any programming language" which is much more difficult to follow. (An alternative would be that the language specific generator adds trailing underscores on demand in cases where the name would collide with a keyword in that language.)

Since the generated DDS API is only internally within the vendor specific typesupport and rmw implementation we didn't spend more time on this. For the future in my opinion ROS 2 needs to be able to interface with existing DDS types defined not by ROS. So there needs to be either a mapping from one DDS type to the ROS-specific DDS type or the ROS-specific DDS type needs to be able to use a custom (not following our convention of `<pkgname>::dds_::<msgname>_` with `<fieldname>_`) mapping. But neither of these topics have been address so far (and are not scheduled on the roadmap atm).

For the `dds_` module I don't recall if there was a rational why it was chosen.

[Visit Topic](https://discourse.ros.org/t/so-many-trailing-underscores/1511/2) or reply to this email to respond.

More information about the ros-users mailing list