Fixing C's Biggest Mistake
Walter Bright
newshound2 at digitalmars.com
Tue Dec 27 22:54:59 UTC 2022
On 12/27/2022 3:32 AM, Dukc wrote:
> The `.init` value is supposed to be both. A null pointer is a good example. It
> is valid in the sense it's behaviour is reliable. Dereferencing it always
> crashes the program, as opposed to undefined behaviour. Also it will reliably
> say yes when compared to another null pointer.
>
> But it is also an useful value for debugging, because accidently using it
> immediately crashes and produces a core dump, making it obvious we had a null
> where there shouldn't be one. Also when debugging, pointer to address
> `0x0000_0000_0000_0000` is clearly uninitialised, while a pointer to whatever
> happens might look like it's pointing to something valid.
D's positive initialization also ensures that instances will not be initialized
with random garbage.
More information about the Digitalmars-d
mailing list