Struct with default ctor (Was: [dmd-beta] dmd 2.064 beta take 2)

Jonathan M Davis jmdavisProg at gmx.com
Sat May 18 23:14:52 PDT 2013


On Saturday, May 18, 2013 22:04:08 Walter Bright wrote:
> On 5/18/2013 9:42 PM, Jonathan M Davis wrote:
> > On Saturday, May 18, 2013 21:30:57 Walter Bright wrote:
> >> On 5/18/2013 9:06 PM, Jonathan M Davis wrote:
> >>> The closest that there is is
> >>> C++'s references, which aren't rebindable and in many ways act more like
> >>> aliases than pointers.
> >> 
> >> You can trivially create null references in C++:
> >> 
> >> int* p = NULL;
> >> int& r = *p;
> > 
> > Yes, but they're designed with the idea that they're non-nullable. You
> > can't assign NULL to them or check if they're NULL. It's just that it's
> > possible to make them NULL by the trick that you just showed.
> 
> I don't even think it's a trick, as it can easily happen unintentionally.

Yes, but it's not something that would be done intentionally, and it's 
something that surprises most people. I expect that the vast majority of C++ 
programmers would think that it's impossible before it was explained to them. 
C++ references are usually sold as being non-nullable, and this is arguably a 
hole in their design.

- Jonathan M Davis


More information about the Digitalmars-d mailing list