digitalmars.D.bugs - Conditional ? bug
- Max Samuha (13/13) Oct 06 2006 class Test
- Tydr Schnubbis (6/21) Oct 06 2006 From http://www.digitalmars.com/d/expression.html#EqualExpression :
- Tydr Schnubbis (3/5) Oct 06 2006 Oops, I meant "test !is null ? test.foo() : 0". "is" and "!is" compares...
- Max Samuha (3/24) Oct 06 2006 Sorry, my fault. I should have used !is or simply test. Thanks
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (6/10) Oct 06 2006 Not entirelly your fault, "== null" and "!= null" is common
- Serg Kovrov (7/7) Oct 06 2006 I like PHP5 syntax for that matter: use == / '!=' to compare values of
- xs0 (4/10) Oct 06 2006 === and !== were in D as well, but supposedly == can't be distinguished
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (3/6) Oct 06 2006 We had those in D too... They got renamed to 'is"'and '!is' in 0.126.
- Unknown W. Brackets (9/18) Oct 06 2006 Well, close, but what he's also saying is that PHP (since 4 actually)
class Test { int foo() { return 1; } } void main() { Test test = null; int i = test != null ? test.foo() : 0; } This throws access violation exception
Oct 06 2006
Max Samuha wrote:class Test { int foo() { return 1; } } void main() { Test test = null; int i = test != null ? test.foo() : 0; } This throws access violation exceptionFrom http://www.digitalmars.com/d/expression.html#EqualExpression : "For class and struct objects, the expression (a == b) is rewritten as a.opEquals(b), and (a != b) is rewritten as !a.opEquals(b)." So you have to use "test != null ? test.foo() : 0" for that kind of thing. Just "test ? test.foo() : 0" works too.
Oct 06 2006
Tydr Schnubbis wrote:So you have to use "test != null ? test.foo() : 0" for that kind of thing. Just "test ? test.foo() : 0" works too.Oops, I meant "test !is null ? test.foo() : 0". "is" and "!is" compares the references, it doesn't turn into a call to opEquals.
Oct 06 2006
On Fri, 06 Oct 2006 13:51:21 +0200, Tydr Schnubbis <fake address.dude> wrote:Max Samuha wrote:Sorry, my fault. I should have used !is or simply test. Thanksclass Test { int foo() { return 1; } } void main() { Test test = null; int i = test != null ? test.foo() : 0; } This throws access violation exceptionFrom http://www.digitalmars.com/d/expression.html#EqualExpression : "For class and struct objects, the expression (a == b) is rewritten as a.opEquals(b), and (a != b) is rewritten as !a.opEquals(b)." So you have to use "test != null ? test.foo() : 0" for that kind of thing. Just "test ? test.foo() : 0" works too.
Oct 06 2006
Max Samuha wrote:Not entirelly your fault, "== null" and "!= null" is common enough to have the D compiler detect them at compile time... Or it could just be defined to "false", like it is in Java. (i.e. "For any non-null reference x, x == null equals false") --andersSo you have to use "test != null ? test.foo() : 0" for that kind of thing. Just "test ? test.foo() : 0" works too.Sorry, my fault. I should have used !is or simply test. Thanks
Oct 06 2006
I like PHP5 syntax for that matter: use == / '!=' to compare values of objects, and === / !== (they call it 'identity operators') to compare references. This 'identity operators' could be used to distinct, say, true (bool) from 1 (int), etc.. Nice stuff. -- serg.
Oct 06 2006
Serg Kovrov wrote:I like PHP5 syntax for that matter: use == / '!=' to compare values of objects, and === / !== (they call it 'identity operators') to compare references. This 'identity operators' could be used to distinct, say, true (bool) from 1 (int), etc.. Nice stuff.=== and !== were in D as well, but supposedly == can't be distinguished from === in some fonts, so they were changed to is and !is.. xs0
Oct 06 2006
Serg Kovrov wrote:I like PHP5 syntax for that matter: use == / '!=' to compare values of objects, and === / !== (they call it 'identity operators') to compare references.We had those in D too... They got renamed to 'is"'and '!is' in 0.126. --anders
Oct 06 2006
Well, close, but what he's also saying is that PHP (since 4 actually) also dropped implicit conversions for them - for example: bool foo = true; int bar = 1; if (foo is bar) writefln("This happens in D but not in PHP."); This gave you a much faster compare, as well. Still, I think it makes sense the way it works now in D, personally. -[Unknown]Serg Kovrov wrote:I like PHP5 syntax for that matter: use == / '!=' to compare values of objects, and === / !== (they call it 'identity operators') to compare references.We had those in D too... They got renamed to 'is"'and '!is' in 0.126. --anders
Oct 06 2006