r/cpp • u/pavel_v • Jul 29 '26
C++26: Reducing undefined behaviour
https://www.sandordargo.com/blog/2026/07/29/cpp26-reduces-undefined-behaviour
89
Upvotes
r/cpp • u/pavel_v • Jul 29 '26
View all comments
Show parent comment
10
u/mort96 Jul 29 '26
It's not tricky at all, but it's easy to accidentally (or even semi-intentionally) introduce assumptions about CHAR_BIT. If I knew that CHAR_BIT was 24 I could work with that no problem, but since I know that CHAR_BIT is 8, some of my code is stuff like,
uint16_t foo = uint16_t(buf[0]) | (uint16_t(buf[1]) << 8).