3 ms·
> See zero initializing variables by default Strictly speaking the standard only requires some pattern that is not tied to program state. Zero works for that,
by aw1621107 17d ago
> See zero initializing variables by default
Strictly speaking the standard only requires some pattern that is not tied to program state. Zero works for that, but so do other static patterns like 0xABAB... or the like.
> (WHY?)
The motivation section of the corresponding paper [0] might be interesting. tl;dr: it lets wrong code be wrong without suffering from (all) the consequences of full-blown UB.
[0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2795r5.html#motivation https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p27...
- fc417fc802 17d agoIn other words, it's a sane default that you can opt out of on a case by case basis which is the way it should have been all along.
- WalterBright 17d agoD initializes floating point variables to NaN by default. And chars to 0xFF. Yes it's controversial!
- dahart 17d agoI’d guess the concern is performance, not what initializer value is used. And performance is a valid concern that is discussed in the proposal, and a reason there’s an escape hatch. Still, it might cause some confusion.
- TuxSH 16d agoAFAIK zero-init is unfortunately the default compiler use (but you can change that)