[RFC] Throwing an exception with null pointers

Derek Fawcus dfawcus+dlang at employees.org
Wed Apr 16 18:43:44 UTC 2025


On Wednesday, 16 April 2025 at 18:19:58 UTC, Walter Bright wrote:
> Thank you, Steven. This is correct.

Yup - I like the crash...

However I do have an interest in being able to write code with 
distinct nullable and nonnull pointers.  That such that the 
compiler (or an SA tool) can complain when they're incorrectly 
confused.

So passing (or assigning) a nullable pointer to a nonnull one 
without a prior check should generate a compile error or warning. 
  That should only require function local DFA.

The reason to want it is simply that test cases may not exercise 
complete coverage for various paths when one only has the C style 
pointer, and so it should allow for easy latent bug detection and 
fixes when one is not bypassing the type system.

If one is bypassing the type system, then one takes the risks, 
but the SIGSEGV is still there to catch the bug.

(Yes, I've programmed under DOS.  I also took advantage of a 
protected mode OS (FlexOS) when available to prove and debug the 
code first.  The TurboC style 'detected a null pointer write' at 
program exit while occasionally useful, was grossly inadequate)


More information about the Digitalmars-d mailing list