Fixing C's Biggest Mistake
Dukc
ajieskola at gmail.com
Tue Dec 27 11:32:51 UTC 2022
On Tuesday, 27 December 2022 at 09:41:59 UTC, Max Samukha wrote:
> If T.init is supposed to be a valid value, then the constructor
> receives an already initialized object (not some "branded"
> abberant), so the constructor actually plays the role of
> assignment.
>
> If T.init is supposed to be an invalid value useful for
> debugging, then variables initialized to that value... are not
> initialized.
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.
More information about the Digitalmars-d
mailing list