[RFC] Throwing an exception with null pointers
Dave P.
dave287091 at gmail.com
Wed Apr 16 19:57:28 UTC 2025
On Wednesday, 16 April 2025 at 19:44:09 UTC, Walter Bright wrote:
> On 4/16/2025 11:43 AM, Derek Fawcus wrote:
>> 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.
>
> That's what templates are for!
I think what people are complaining about isn’t that null
pointers exist at all, it’s that every pointer and reference type
has a null value instead of you opting into it. The type system
fights you if you want to use it to prove or enforce certain
values are nullable or not.
Something that people don’t bring up is that clang’s nullability
extension allows you to change what the default is. You put a
`#pragma clang assume_nonnull begin` at the top of your
C/C++/Objective-C code and you have to annotate only the nullable
pointers. Most pointers in a program should be non-null and the
nullable ones should be the exception that you have to annotate.
More information about the Digitalmars-d
mailing list