Am Dienstag, dem 16.12.2025 um 10:36 +0100 schrieb Bruno Haible:
> 
...

> > > I'd prefer Clang's _Nullable keyword, if we're going to do that.
> > 
> > I prefer _Optional, because this works correctly.
> 
> But the syntax for _Optional is broken: While one can write (in clang)
> 
>   int *_Nonnull x;
>   int *_Nullable y;
> 
> the n3422 proposal wants us to write
> 
>   _Optional int *y;
> 
> with the twisted logic of "Let’s reframe the 'may be null' property as
> a quality of the pointed-to object, rather than the pointer" !!!

This exactly what makes _optional work correctly as qualifier.

With one exception, a qualifier in C has two properties:

1. It affects lvalue conversion but is meaningless for the value.
For example:

const int i = 3;

int r = i + 1;  // here the const is irrelevant after lvaleue conversion

2. It follows certain rules during pointer conversions, i.e. one
can add qualifiers to a pointer target in implicit conversions
but not remove them.

For example:

float x;
const float y = 1;

void foo(const float *x);
void bar(float *y);

foo(&x); // this is allowed as "const" is added automatically
bar(&y); // you get the expected error



_Optional is designed to follow these rules, while _Nonnull and
_Nullable do not.


Martin

Reply via email to