Pointers vs. References

Georg Wrede georg at nospam.org
Wed Jun 13 05:36:13 PDT 2007


Jarrett Billingsley wrote:
> "Ary Manzana" <ary at esperanto.org.ar> wrote in message 
> news:f4ombu$16mp$1 at digitalmars.com...
> 
>>Can't writing
>>
>>x == null, x != null
>>
>>be rewritten by the compiler to
>>
>>x is null, x !is null
>>
>>?
>>
>>
>>I think the two firsts will always segfault. When would a user want to 
>>segfault her program? Or, better asked, when would a user want to do x == 
>>null?
> 
> 
> I don't think the compiler should rewrite it, but I don't think it should be 
> allowed either.  Either make it a warning or an error to ==/!= to null. 

Count me in.

While I'd prefer to use x == null, I can understand that it may be bad 
from a language design point. It would create an anomaly (because it 
artificially avoids calling a member function) which is misleading and 
requires one to remember it when reasoning about the language.

So, instead, it should not be allowed. It should be an error.

It is a construct the programmer didn't intend to write. :-)
And which will bite him, period.



More information about the Digitalmars-d mailing list