Should I compare pointers with is of == ?

Jeremie Pelletier jeremiep at
Wed Oct 14 07:26:34 PDT 2009

Steven Schveighoffer wrote:
> On Wed, 14 Oct 2009 08:15:01 -0400, #ponce <aliloko at> wrote:
>> It's a bit unclear to me.
>> I know I must compare references with is but pointers ?
> Like Moritz said, there is no semantic difference with pointers, but you 
> may consider comparing with is if you are looking for equivalence.  It 
> cannot ever be overridden, so if for some reason you decided to change 
> your pointer to a class reference, it doesn't accidentally morph into a 
> virtual call (possibly to a null object causing a segfault).
> -Steve

I agree, I only learned recently that == is not a direct pointer 
comparison for classes, I had to scramble all around my code to replace 
them with is and !is, so for good habit I'd go with using is for pointer 
equality too.


More information about the Digitalmars-d-learn mailing list