References in D
Jonathan M Davis
jmdavisProg at gmx.com
Thu Oct 4 09:42:26 PDT 2012
On Thursday, October 04, 2012 13:14:00 Alex Burton, @gmail.com wrote:
> On Saturday, 15 September 2012 at 21:30:03 UTC, Walter Bright
>
> wrote:
> > On 9/15/2012 5:39 AM, Henning Pohl wrote:
> >> The way D is dealing with classes reminds me of pointers
> >> because you can null
> >> them. C++'s references cannot (of course you can do some nasty
> >> casting).
> >
> > Doing null references in C++ is simple:
> >
> > int *p = NULL;
> > int& r = *p;
> >
> > r = 3; // crash
>
> IMHO int * p = NULL is a violation of the type system and should
> not compile.
> NULL can in no way be considered a pointer to an int.
Um. What? It's perfectly legal for pointers to be null. The fact that *p
doesn't blow up is a bit annoying, but it makes sense from an implementation
standpoint and doesn't really cost you anything other than a bit of locality
between the bug and the crash.
> In the same way this should fail:
> Class A
> {
>
> }
> A a;
And why would this fail? It's also perfectly legal.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list