| |
| ▲ | 1718627440 9 hours ago | parent | next [-] | | I don't know, I expect all variables to be uninitialized until proven otherwise. It makes it easier for me to reason about code, especially convoluted code. But I also like C a lot and actually explicitly invoke UB quite often, so there is that. | | |
| ▲ | forrestthewoods 9 hours ago | parent [-] | | I like C and it's great. I wish more people wrote C instead of C++. But there's a reason that literally no modern language makes this choice. If uninitialization was opt-in you would still be free to "assume uninitialized until proven otherwise". But uninitialized memory is such a monumental catastrophic footgun that really is not a justifiable reason to make that default behavior. Which, again, is why no modern languages make that (terrible) design choice. | | |
| ▲ | kevin_thibedeau 6 hours ago | parent | next [-] | | There are non-standard mechanisms to control variable initialization. GCC has -ftrivial-auto-var-init=zero for zero-init of locals (with some caveats). For globals, you can link them into a different section than bss to disable zero-init. | |
| ▲ | 1718627440 8 hours ago | parent | prev [-] | | I am talking about random convoluted code, I did neither wrote nor control. The UB does not only help the compiler, it also helps me the reverse engineer, since I also can assume that an access without a previous write is either a bug, or I misinterpreted the control flow. | | |
| ▲ | AlotOfReading 7 hours ago | parent [-] | | 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: realloc(p, 0)
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. | | |
| ▲ | AlotOfReading 3 hours ago | parent | next [-] | | All of that implementation freedom is also available if the behavior is erroneous instead. Having it defined as UB just gets you nasal demons, which incidentally this rule leads to on modern compilers. For example: https://godbolt.org/z/ncaKGnoTb | |
| ▲ | forrestthewoods an hour ago | parent | prev [-] | | Yeah that’s just really bad language design. Which, again, literally no modern languages do because it’s just terrible horrible awful no good very bad design. |
|
|
|
|
| |
| ▲ | 10 hours ago | parent | prev [-] | | [deleted] |
|