Struct with default ctor (Was: [dmd-beta] dmd 2.064 beta take 2)
Simen Kjaeraas
simen.kjaras at gmail.com
Sun May 19 05:02:39 PDT 2013
On Sun, 19 May 2013 06:57:16 +0200, Walter Bright
<newshound2 at digitalmars.com> wrote:
>> The current solution is to rely on faith, and I remember someone
>> talking about
>> that at DConf recently.
>
> Rely on what faith?
void foo(int* p) {} // p must never be null
void foo(NotNull!(int*) p) {}
One of these is tested at compile time, *and* includes valuable
documentation in the signature. The other is either less performant
or buggy.
>> Now that what other languages does is cleared, let's do some
>> consideration on null.
>>
>> A pointer point on something. For instance, an int* point on an
>> integer. null
>> doesn't point on a integer. Non nullable pointer aren't a restricted
>> set of
>> values, as, by definition, null isn't a value that point to an int.
>> That doesn't
>> stand either.
>
> By definition? Pointer semantics are what we choose it to mean.
Of course. But which definition is saner:
"T* is either a valid pointer to a T, or a value that blows up when used
in certain ways (but not others)."
or
"T* is a valid pointer to T."
Of course, the latter also requires something like Maybe!T:
"Maybe!T is either a valid pointer to a T, or a value on which no
operations may be performed. In order to gain access to the T, both
cases have to be handled."
--
Simen
More information about the Digitalmars-d
mailing list