| ▲ | AlotOfReading 6 hours ago | |||||||||||||
You can assume whatever initialization you want when reading code, even if it's not in the standard. Is your concern that people would start writing code assuming zero-init behavior (as they already do)? That purpose would be better served by reclassifying uninitialized reads as erroneous behavior, which they are for C++26 onwards. What useful purpose is served by having them be UB specifically? | ||||||||||||||
| ▲ | torstenvl 3 hours ago | parent [-] | |||||||||||||
UB doesn't mean there will be nasal demons. It means there can be nasal demons, if the implementation says so. It means the language standard does not define a behavior. POSIX can still define the behavior. The implementation can still define the behavior. Plenty of things are UB just because major implementations do things wildly differently. For example:
Having initialization be UB means that implementations where it's zero cost can initialize them to zero, or implementations designed for safety-critical systems can initialize them to zero, or what have you, without the standard forcing all implementations to do so. | ||||||||||||||
| ||||||||||||||