The NaN of types (in D)
Stefan Koch
uplink.coder at googlemail.com
Mon Oct 12 15:10:55 UTC 2020
On Monday, 12 October 2020 at 15:03:07 UTC, Paul Backus wrote:
> On Monday, 12 October 2020 at 14:46:14 UTC, Joseph Rushton
> Wakeling wrote:
>> On Monday, 12 October 2020 at 14:11:22 UTC, Paul Backus wrote:
>>> The issue with null references is not related to memory
>>> safety. NullPointerException in Java is not a memory-safety
>>> error, for example. The issue with nullable references is
>>> that you have to check every reference for null before you
>>> use it, or your program will crash.
>>>
>>> By contrast, NaN will not crash your program if you forget to
>>> check for it before using it in an expression.
>>
>> Right. I'm just not sure I follow why the ø Stefan is
>> defining wouldn't behave more like NaN than a null pointer.
>
> Since ø is not a type, I assume that you will get an error if
> you try to use it for anything that requires a type--for
> example, declaring a variable, or asking for its .sizeof.
>
> If this is not the case, I invite Stefan to correct me.
You cannot create a variable of type ø.
ø myVar; is invalid.
You cannot ø as a returnType or as a parameter type.
So a functiondeclatation like ø fn(int x) or int fn(ø x) is
invalid.
But you can ask for it's size.
ø.sizeof == 0.
For it's members
__traits(allMembers, ø) == []
....
And I think that's all of the introspection I currently support.
__traits(getAttributes) is currently not available anymore as I
need to define, a type which can hold anything (and not just
types) for that to work.
More information about the Digitalmars-d
mailing list