digitalmars.D.learn - Std.boxer toString() w/ Objects or Structs.
- AJG (6/6) Aug 16 2005 Hi,
- Ben Hinkle (6/14) Aug 17 2005 I can't reproduce any problem with objects - perhaps you mean interfaces...
- AJG (27/45) Aug 17 2005 Hi,
- Ben Hinkle (3/12) Aug 17 2005 If you are referring to my reply I said cast an interface to Object - no...
- AJG (9/19) Aug 17 2005 Whoops. Misread that sentence a little bit ;)
- Ben Hinkle (4/10) Aug 17 2005 I think it does whatever std.format.doFormat does with a struct - probab...
- AJG (8/15) Aug 17 2005 Hi,
Hi, I'm using boxes with relative ease and everything seems to be working properly. I have a problem with the Box.toString() method, though. Is there a way to make it work with objects or structs? Thanks, --AJG.
Aug 16 2005
"AJG" <AJG_member pathlink.com> wrote in message news:ddubsm$1llp$1 digitaldaemon.com...Hi, I'm using boxes with relative ease and everything seems to be working properly. I have a problem with the Box.toString() method, though. Is there a way to make it work with objects or structs? Thanks, --AJG.I can't reproduce any problem with objects - perhaps you mean interfaces? With structs there's no default toString. Note when boxing an interface I think you need to explicitly cast it to Object before boxing but I'm not sure.
Aug 17 2005
Hi, So for example, what do you get here: I get: Test=nan Or something like that. (Don't have a compiler available; please excuse any typos in there). I would like to get: Test=4.2 ------ Also, what does casting a struct to an Object do? Seems kinda weird, going from value to reference? Thanks, --AJG. In article <ddviv4$2u8f$1 digitaldaemon.com>, Ben Hinkle says..."AJG" <AJG_member pathlink.com> wrote in message news:ddubsm$1llp$1 digitaldaemon.com...Hi, I'm using boxes with relative ease and everything seems to be working properly. I have a problem with the Box.toString() method, though. Is there a way to make it work with objects or structs? Thanks, --AJG.I can't reproduce any problem with objects - perhaps you mean interfaces? With structs there's no default toString. Note when boxing an interface I think you need to explicitly cast it to Object before boxing but I'm not sure.
Aug 17 2005
Or something like that. (Don't have a compiler available; please excuse any typos in there). I would like to get: Test=4.2I get Test=4.2 on Windows using dmd.129------ Also, what does casting a struct to an Object do? Seems kinda weird, going from value to reference?If you are referring to my reply I said cast an interface to Object - not struct to Object. You can't cast a struct to Object as you probably guessed.
Aug 17 2005
Hi,Will have to try that again soon. Thanks.Or something like that. (Don't have a compiler available; please excuse any typos in there). I would like to get: Test=4.2I get Test=4.2 on Windows using dmd.129Whoops. Misread that sentence a little bit ;) Though I was kind of interested in the struct to object casting, hypothetically. Could be a way to automagically pass from the stack to the GC heap. Ok, anyway, then what is the expected result when you toString() a box with a struct? Is there a defined behaviour? Thanks again, --AJG.Also, what does casting a struct to an Object do? Seems kinda weird, going from value to reference?If you are referring to my reply I said cast an interface to Object - not struct to Object. You can't cast a struct to Object as you probably guessed.
Aug 17 2005
Though I was kind of interested in the struct to object casting, hypothetically. Could be a way to automagically pass from the stack to the GC heap. Ok, anyway, then what is the expected result when you toString() a box with a struct? Is there a defined behaviour?I think it does whatever std.format.doFormat does with a struct - probably throw a FormatError exception. ps - I wish Walter would do something about the Error vs Exception naming "convention"...
Aug 17 2005
Hi, First- you were right about Objects. There was a ridiculously diabolical bug in my code.Hm... I even tried a toString() method in my struct and it still crashed and burnt. It would seem logical to me to call this method for a struct too.Ok, anyway, then what is the expected result when you toString() a box with a struct? Is there a defined behaviour?I think it does whatever std.format.doFormat does with a struct - probably throw a FormatError exception.ps - I wish Walter would do something about the Error vs Exception naming "convention"...Yes. This is entirely misleading. Thanks, --AJG.
Aug 17 2005