Remix.run Logo
aw1621107 7 hours 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/p27...

dahart an hour ago | parent | next [-]

I’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.

WalterBright 4 hours ago | parent | prev | next [-]

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

fc417fc802 5 hours ago | parent | prev [-]

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.