Hacker News new | ask | show | jobs
by Conscat 1314 days ago
There's one big difference between undefined behavior in C and C++. In C++, undefined behavior is ill-formed when it is constant-evaluated. And for aspects which are tricky to determine undefined behavior for, such as reinterpret_cast or type-punning in a union, they're just disallowed in constexpr code entirely. So in C++, you can't necessarily just say "well this is undefined, but it works correctly within our particular constraints", whereas you always can say that in C. That makes implementation-defined a huge difference from undefined. You can always cast signed integers to unsigned integers or vice versa in constexpr code.