[RFC] Throwing an exception with null pointers

Derek Fawcus dfawcus+dlang at employees.org
Wed Apr 16 23:08:37 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 can't say I've played with them much, having come from C not 
C++.

I see there is the ability to overload the unary '*' operator, 
and so can imagine how one could define a struct providing a 
non-null form of pointer.

But just how awkward is that going to be for mixed forms of 
nullability in function definitions.  Without trying, i suspect 
it will just get too awkward.

e.g., how would the equivalent of this args end up in a D 
rendition:

```C
int foo(char * _Nonnull * _Nullable a, int * _Nullable * _Nonnull 
b);
```


More information about the Digitalmars-d mailing list