Why does nobody seem to think that `null` is a serious problem in D?
aliak
something at something.com
Sun Dec 2 23:36:16 UTC 2018
On Saturday, 1 December 2018 at 19:02:54 UTC, H. S. Teoh wrote:
>
> In the above contrived example, Artin's conjecture is implied
> by the Riemann hypothesis, so the second if statement would
> only run if p is initialized. But there is no way the compiler
> is going to be able to deduce this, especially not during
> compile time. So it is not possible to correctly flag p as
> being initialized or not when it is dereferenced.
>
> Therefore, leaving it up to the compiler to detect
> uninitialized variables is unreliable, and therefore any code
> that depends on this cannot be trusted. Code like the above
> could be exploited by a sufficiently sophisticated hack to make
> the uninitialized value of p coincide with something that will
> open a security hole, and the compiler would not be able to
> reliably warn the programmer of this problem.
>
> Uninitialized variables are *not* a good thing, contrary to
> what the author of the article might wish to believe.
>
>
> T
If a compiler were to issue warnings/error for uninitialized
variables. Then that example would be a compiler error. The logic
would just be that not all code paths lead to an initialized
variable, therefor *p++ is not guaranteed to be initialized -
i.e. error. Swift takes this approach.
Cheers,
- Ali
More information about the Digitalmars-d-learn
mailing list