diff --git a/include/fastrtps/rtps/common/EntityId_t.hpp b/include/fastrtps/rtps/common/EntityId_t.hpp index e0a2121bf67..fd781f76226 100644 --- a/include/fastrtps/rtps/common/EntityId_t.hpp +++ b/include/fastrtps/rtps/common/EntityId_t.hpp @@ -327,8 +327,21 @@ struct hash std::size_t operator()( const eprosima::fastrtps::rtps::EntityId_t& k) const { - const uint32_t* aux = reinterpret_cast(k.value); - return static_cast(*aux); + // recover the participant entity counter + eprosima::fastrtps::rtps::octet value[4]; + +#if __BIG_ENDIAN__ + value[3] = k.value[2]; + value[2] = k.value[1]; + value[1] = k.value[0]; + value[0] = 0; +#else + value[3] = 0; + value[2] = k.value[0]; + value[1] = k.value[1]; + value[0] = k.value[2]; +#endif + return static_cast(*reinterpret_cast(&value)); } };