2 ms·
Boost.Endian is the library here and this code is safe because the big_uint32_t type has an alignment requirement of 1 byte. This is why ubsan is silent and no
by nly 6y ago
Boost.Endian is the library here and this code is safe because the big_uint32_t type has an alignment requirement of 1 byte.
This is why ubsan is silent and not even injecting a check in to the compiled code.
You can check the alignment constraints with static_assert (something else you can't do in standard C): https://gcc.godbolt.org/z/KTcf9ax6r https://gcc.godbolt.org/z/KTcf9ax6r
- kevin_thibedeau 6y agoC11 has static_assert: https://gcc.godbolt.org/z/E3bGc95o3 https://gcc.godbolt.org/z/E3bGc95o3 Is also has _Generic() so you can roll up a family of endianness conversion functions and safely change types without blowing up somewhere else with a hardcoded conversion routine.