digitalmars.D - Default value of class
- David B. Held (11/11) May 19 2007 Can anyone tell me the expected runtime behavior of this program?
- Dave (2/17) May 19 2007 Try 'assert(foo is null);'
- davidb (5/30) May 20 2007 which will fail if a is null because it can't use it to reference to
- David B. Held (5/37) May 20 2007 Aha...thanks guys. However, I am disturbed by two things: 1) that this
- Chris Nicholson-Sauls (5/44) May 20 2007 o_O It only makes sense though, for a language named "D".
- Jarrett Billingsley (3/4) May 20 2007 Well, maybe VB got some things right ;)
- Daniel Keep (12/17) May 20 2007 It's still the only language I've seen that lets me pass temporaries and
- Jarrett Billingsley (5/13) May 20 2007 Doesn't C++ have those ... && reference arguments? Like int&& ? You ca...
- Jarrett Billingsley (22/25) May 20 2007 Though D can do this:
- Daniel Keep (22/62) May 20 2007 That's interesting; could that be NVRO? That said, this still doesn't
Can anyone tell me the expected runtime behavior of this program? class Foo { } void main() { Foo foo; assert(foo == null); } It's certainly not what I expected, and I want to know if I should file a bug report or not. Dave
May 19 2007
David B. Held wrote:Can anyone tell me the expected runtime behavior of this program? class Foo { } void main() { Foo foo; assert(foo == null); } It's certainly not what I expected, and I want to know if I should file a bug report or not. DaveTry 'assert(foo is null);'
May 19 2007
Dave schrieb:David B. Held wrote:See http://www.digitalmars.com/d/operatoroverloading.htmlCan anyone tell me the expected runtime behavior of this program? class Foo { } void main() { Foo foo; assert(foo == null); } It's certainly not what I expected, and I want to know if I should file a bug report or not. DaveTry 'assert(foo is null);'Note: Comparing a reference to a class object against null should be done as:which will fail if a is null because it can't use it to reference to opEquals() davidif (a is null)and not as:if (a == null)The latter is converted to:if (a.opEquals(null))
May 20 2007
davidb wrote:Dave schrieb:Aha...thanks guys. However, I am disturbed by two things: 1) that this looks more like VB than C++ ;), and 2) that everyone in this thread is named "David". Hmm... DaveDavid B. Held wrote:See http://www.digitalmars.com/d/operatoroverloading.html > Note: Comparing a reference to a class object against null should be > done as: >> if (a is null) > and not as: >> if (a == null) > The latter is converted to: >> if (a.opEquals(null)) which will fail if a is null because it can't use it to reference to opEquals()Can anyone tell me the expected runtime behavior of this program? class Foo { } void main() { Foo foo; assert(foo == null); } It's certainly not what I expected, and I want to know if I should file a bug report or not. DaveTry 'assert(foo is null);'
May 20 2007
David B. Held wrote:davidb wrote:o_O It only makes sense though, for a language named "D". We have our army of Davids, and the (Ch|K)ris's... at least there's just one Walter. Could you imagine... -- Chris (!) Nicholson-SaulsDave schrieb:Aha...thanks guys. However, I am disturbed by two things: 1) that this looks more like VB than C++ ;), and 2) that everyone in this thread is named "David". Hmm... DaveDavid B. Held wrote:See http://www.digitalmars.com/d/operatoroverloading.html > Note: Comparing a reference to a class object against null should be > done as: >> if (a is null) > and not as: >> if (a == null) > The latter is converted to: >> if (a.opEquals(null)) which will fail if a is null because it can't use it to reference to opEquals()Can anyone tell me the expected runtime behavior of this program? class Foo { } void main() { Foo foo; assert(foo == null); } It's certainly not what I expected, and I want to know if I should file a bug report or not. DaveTry 'assert(foo is null);'
May 20 2007
"David B. Held" <dheld codelogicconsulting.com> wrote in message news:f2ptar$2022$1 digitalmars.com...this looks more like VB than C++Well, maybe VB got some things right ;)
May 20 2007
Jarrett Billingsley wrote:"David B. Held" <dheld codelogicconsulting.com> wrote in message news:f2ptar$2022$1 digitalmars.com...It's still the only language I've seen that lets me pass temporaries and literals as reference arguments... :) -- int getRandomNumber() { return 4; // chosen by fair dice roll. // guaranteed to be random. } http://xkcd.com/ v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/this looks more like VB than C++Well, maybe VB got some things right ;)
May 20 2007
"Daniel Keep" <daniel.keep.lists gmail.com> wrote in message news:f2qf8m$2v85$1 digitalmars.com...Jarrett Billingsley wrote:Doesn't C++ have those ... && reference arguments? Like int&& ? You can pass temps to those. Well I guess those are in C++09, so they're not part of the language yet."David B. Held" <dheld codelogicconsulting.com> wrote in message news:f2ptar$2022$1 digitalmars.com...It's still the only language I've seen that lets me pass temporaries and literals as reference arguments... :)this looks more like VB than C++Well, maybe VB got some things right ;)
May 20 2007
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:f2qgao$3176$1 digitalmars.com...Doesn't C++ have those ... && reference arguments? Like int&& ? You can pass temps to those. Well I guess those are in C++09, so they're not part of the language yet.Though D can do this: struct S { int x; static S opCall(int x) { S s; s.x = x; return s; } } void foo(ref S s) { writefln(s.x); } void main() { foo(S(4)); } Which I guess is pretty close.
May 20 2007
Jarrett Billingsley wrote:"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:f2qgao$3176$1 digitalmars.com...That's interesting; could that be NVRO? That said, this still doesn't work...Doesn't C++ have those ... && reference arguments? Like int&& ? You can pass temps to those. Well I guess those are in C++09, so they're not part of the language yet.Though D can do this: struct S { int x; static S opCall(int x) { S s; s.x = x; return s; } } void foo(ref S s) { writefln(s.x); } void main() { foo(S(4)); } Which I guess is pretty close.import std.stdio; void foo(ref int a) { writefln("a: %s", a); } void main() { foo(42); }H:\WINDOWS\system32\cmd.exe /c bud -clean -exec refargs refargs.d(11): Error: constant 42 is not an lvalue :( This is a pain because I discovered that using ref arguments for my vector library can net me a *big* speed increase, even more so once I put in SSE optimisations. The problem is that if I can't pass literals or temporaries, then it'll render the library much harder to use. Then again, maybe since the vectors are structs, the above will work... need to give that a shot when I'm not so busy. -- int getRandomNumber() { return 4; // chosen by fair dice roll. // guaranteed to be random. } http://xkcd.com/ v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
May 20 2007