boost::endian::native_to_big_inplace fails with char
18 Mar
2019
18 Mar
'19
3:47 p.m.
I am having issues with boost::endian:native_to_big_inplace when used with a char. Whatever you try to 'reverse' comes out as 0. Looking through the code, on little endian machines it calls endian_reverse (as expected). This function has no overload for a char and it then gets promoted to an int. Since the int _is_ actually larger than 1 byte, something gets reversed. The native_to_big_inplace then returns it as a char, narrowing the int and throwing away all the relevant bits, resulting in a 0. I found an issue on github about this: https://github.com/boostorg/endi an/issues/10 about exactly this issue. The bug is easily shown if you try to compile static_assert(sizeof(boost::endian::endian_reverse('y')) == sizeof('y'))
2068
Age (days ago)
2068
Last active (days ago)
0 comments
1 participants
participants (1)
-
Martijn Otto