logoalt Hacker News

aw1621107yesterday at 6:45 PM2 repliesview on HN

> 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/p27...


Replies

WalterBrightyesterday at 10:10 PM

D initializes floating point variables to NaN by default. And chars to 0xFF. Yes it's controversial!

fc417fc802yesterday at 9:41 PM

In 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.