2 ms·
UB is bad not because it actually leads to any particular result on any particular platform or compiler, but because semantically it invalidates assumptions abo
by LoganDark 3mo ago
UB is bad not because it actually leads to any particular result on any particular platform or compiler, but because semantically it invalidates assumptions about a program. Rust is explicit on this, but it absolutely still applies to C/C++.
- em3rgent0rdr 3mo agoWell because it could lead to any result on some platform or compiler, it invalidates assumptions about the program.
- LoganDark 3mo agoUB invalidates assumptions about the program not necessarily because it leads to arbitrary behavior in practice, but because it leads to arbitrary behavior in spirit. Even if there is no compiler in existence where the UB causes a problem, that does not make the program correct. UB is about whether the program is correctly defined, not about whether it works or not.