4 ms·
Just look at this: https://blog.habets.se/2026/05/Everything-in-C-is-undefined-behavior.html https://blog.habets.se/2026/05/Everything-in-C-is-undefined-... Th
by FooBarWidget 1mo ago
Just look at this: https://blog.habets.se/2026/05/Everything-in-C-is-undefined-behavior.html https://blog.habets.se/2026/05/Everything-in-C-is-undefined-...
This is undefined behavior!
const int* magic_intp = (const int*)bytes;
Heck even something trivial like this is UB:
bool bar(char ch) { return isxdigit(ch); }
The only safe thing to do is memcpy, but that's super useless. As soon as you try to interpret or manipulate the byte-level data in any way, there are UB traps everywhere you go.
- deleted 1mo ago[deleted]
- uecker 1mo agoYes, using an arbitrary type that is different from the one of the object is UB. But any access of a representation byte using a character pointer is well defined, not just memcpy and I would also not call memcpy useless.