www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Equality for Objects (documentation)

reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
http://www.digitalmars.com/d/expression.html#EqualExpression says:

 Equality Expressions
 
 	EqualExpression == RelExpression
 	EqualExpression != RelExpression
 	EqualExpression is RelExpression
 
 Equality expressions compare the two operands for
 equality (==) or inequality (!=). The type of the result is bool.
There is no "bool" type, the type of the result is int. (bool is just defined as an alias for bit, in object.d)
 For class objects, equality is defined as the result of calling Object.eq().
The name of the method called is now opEquals, not "eq" As in: "The names of the overloaded operators may change."
 If one or the other or both objects are null, an exception is raised.
And it does not throw an exception, but just dereference null. Which usually leads to a Segmentation Fault / Access Violation. --anders PS. Identity Expressions is missing from the page index... And '===' should probably be listed in that section ?
Jan 12 2005
parent reply "Simon Buchan" <buchan.home ihug.co.nz> writes:
On Wed, 12 Jan 2005 12:38:51 +0100, Anders F Björklund <afb algonet.se>  
wrote:

 http://www.digitalmars.com/d/expression.html#EqualExpression says:

 Equality Expressions
  	EqualExpression == RelExpression
 	EqualExpression != RelExpression
 	EqualExpression is RelExpression
  Equality expressions compare the two operands for
 equality (==) or inequality (!=). The type of the result is bool.
There is no "bool" type, the type of the result is int. (bool is just defined as an alias for bit, in object.d)
 For class objects, equality is defined as the result of calling  
 Object.eq().
The name of the method called is now opEquals, not "eq" As in: "The names of the overloaded operators may change."
 If one or the other or both objects are null, an exception is raised.
And it does not throw an exception, but just dereference null. Which usually leads to a Segmentation Fault / Access Violation.
Both are just exceptions (0xC0000005 familiar?). Tricky, eh?
 --anders

 PS. Identity Expressions is missing from the page index...
      And '===' should probably be listed in that section ?
anyone know whether === is actually depreciated if favour of 'is', or are both A-OK? -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jan 14 2005
parent reply =?ISO-8859-15?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Simon Buchan wrote:

 And it does not throw an exception, but just dereference null.
 Which usually leads to a Segmentation Fault / Access Violation.
Both are just exceptions (0xC0000005 familiar?). Tricky, eh?
No, it's not familiar (then again, I don't run Windows either...) Here it is more like:
 Program received signal EXC_BAD_ACCESS, Could not access memory.
 0x0000260c in _Dmain ()
 (gdb) 
You are saying a hardware exception is the same thing as Exception? Just because they have similar names on a certain operating system? So maybe that is what Walter is talking about on the doc page... I assumed regular exceptions, since "raise" is a synonym for "throw" Maybe something like "If one or the other or both objects are null, your program will horribly crash." would be more easy understandable?
 anyone know whether === is actually depreciated if favour of 'is',
 or are both A-OK?
According to the DMD 0.110 source code, both map to TOKidentity. But there is just one mapping to TOKnotidentity, and that is !== Could be nice if the documentationed mentioned both, and used one? --anders
Jan 14 2005
parent "Simon Buchan" <buchan.home ihug.co.nz> writes:
On Fri, 14 Jan 2005 10:35:05 +0100, Anders F Björklund <afb algonet.se>  
wrote:

 Simon Buchan wrote:

 And it does not throw an exception, but just dereference null.
 Which usually leads to a Segmentation Fault / Access Violation.
Both are just exceptions (0xC0000005 familiar?). Tricky, eh?
No, it's not familiar (then again, I don't run Windows either...) Here it is more like:
 Program received signal EXC_BAD_ACCESS, Could not access memory.
 0x0000260c in _Dmain ()
 (gdb)
You are saying a hardware exception is the same thing as Exception? Just because they have similar names on a certain operating system?
Pretty much. in thread "'===' Revisited" in digitalmars.D, Walter Bright says:
 The null check is being done. It's just being done "for free" by the
 hardware. You can also catch access violation exceptions just like any  
 other
 exception. There really isn't anything added by doing a redundant check  
 in
 software, other than bloat.
 So maybe that is what Walter is talking about on the doc page...
 I assumed regular exceptions, since "raise" is a synonym for "throw"

 Maybe something like "If one or the other or both objects are null,
 your program will horribly crash." would be more easy understandable?
as will the billion other things that cause SIGSEGV (the name in the Linux kernel, and what is shown on the less forgiving distros) if you don't catch them, as with other exceptions that arn't caught. Just be aware that a message being printed on stdout and your program exiting isn't what I call a horrible crash. That would be when your machine locks up and your hard-drive starts to shred itself- aparantly a possiblity before exceptions/hardware error flags.
 anyone know whether === is actually depreciated if favour of 'is',
 or are both A-OK?
According to the DMD 0.110 source code, both map to TOKidentity. But there is just one mapping to TOKnotidentity, and that is !== Could be nice if the documentationed mentioned both, and used one? --anders
Hmm... not really saying if one or the other is prefered. The doc's are rather scitzofrenic (sp?) on this count, too, some pages only mention in, and say to use !(a in b), others only mention ===, !== -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jan 14 2005