References in D

Alex Rønne Petersen alex at lycus.org
Sun Sep 16 04:47:57 PDT 2012


On 16-09-2012 13:33, Jacob Carlborg wrote:
> On 2012-09-15 23:30, Walter Bright wrote:
>
>> Doing null references in C++ is simple:
>>
>> int *p = NULL;
>> int& r = *p;
>>
>> r = 3; // crash
>
> Won't that crash at the first assignment of "r", since you dereferencing
> a null pointer?.
>

Nope, since in this context you're assigning it to an int&. So it really 
just means "r = p" if you assume that references are just pointers 
(which they are in most implementations).

D works like this too, if you pass a *p to a ref parameter and such.

-- 
Alex Rønne Petersen
alex at lycus.org
http://lycus.org


More information about the Digitalmars-d mailing list