Fixing C's Biggest Mistake

Max Samukha maxsamukha at gmail.com
Tue Dec 27 19:12:13 UTC 2022


On Tuesday, 27 December 2022 at 11:32:51 UTC, Dukc wrote:
> On Tuesday, 27 December 2022 at 09:41:59 UTC, Max Samukha 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.

I'd say it is invalid, but using it results in deterministic 
behavior. Hence "invalid but good for debugging".

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

Yeah, but in case of an int, you never can tell whether the 
programmer wanted to initialize it to 0 or forgot to initialize 
it.



More information about the Digitalmars-d mailing list