4 ms·
The code you're compiling is flat-out wrong though. This is exactly a nasal demons situation. Since `Do` is static, the compiler can guarantee that the only pos
by 0xTJ 6y ago
The code you're compiling is flat-out wrong though. This is exactly a nasal demons situation. Since `Do` is static, the compiler can guarantee that the only possible place it could be set in this file is in `NeverCalled`. Since calling `Do` is only ever valid after that line in `NeverCalled`, it can safely assume that you'd only ever call `Do` after it's been set to `EraseAll`. Anything else is 100% undefined behaviour. You should have a check on the value of `Do` or have a default value.
- teraflop 6y agoI don't think OP is arguing that this is a violation of the language spec; they're arguing that the spec (as implemented) is stupid.
- dale_glass 6y agoRight, and that's one of the things that makes C a bad language for security sensitive issues -- not just that it'll let you use memory after free(), but also that compilers have a liking for doing creative interpretations.
- kevinmgranger 6y agoThis boils down to "just don't do undefined behavior". It's 100% correct and misses the point entirely.[1] 1: https://nibblestew.blogspot.com/2020/04/your-statement-is-100-correct-but.html https://nibblestew.blogspot.com/2020/04/your-statement-is-10...
- bobbylarrybobby 6y agoWhat's wrong with a compiler error? "You are calling a function (Do) that is only defined by calling a function (NeverCalled) that we can't guarantee you ever call"