D - Yet another property idea
- Russell Borogove (12/12) May 19 2002 The property .symbol produces a text string corresponding
- Walter (4/10) May 19 2002 I might be missing something, but what is the advantage over:
- Jonathan Andrew (12/25) May 20 2002 I suppose you could write a generic debug function i.e.
- Pavel Minayev (4/10) May 20 2002 Being resolved at compile time, it'd write "var = 666" (since
- OddesE (21/33) May 20 2002 class Foo
- Patrick Down (3/14) May 20 2002 obj.classinfo.name
- Pavel Minayev (5/16) May 20 2002 Actually, it'd print "obj" (it's the name of the _symbol_,
- OddesE (10/29) May 21 2002 You are right ofcourse!
- Sean L. Palmer (5/35) May 21 2002 So does obj.symbol give its type name, or its value's name? Variable na...
- Jonathan Andrew (3/15) May 21 2002 Hmm, good point.
The property .symbol produces a text string corresponding to the identifier it's applied to: int foo = 3; printf( "%s = %d\n", foo.symbol, foo ); // print "foo = 3" This is purely a compile time operation, generating string representations only on demand. This kind of thing is indispendable for debugging, and valuable in general use as well. IMO, it offers a slight improvement on the "Arrays that parallel an enum" suggestion in: http://www.digitalmars.com/d/ctod.html#arrayenum -RB
May 19 2002
"Russell Borogove" <kaleja estarcion.com> wrote in message news:3CE82DF2.70608 estarcion.com...The property .symbol produces a text string corresponding to the identifier it's applied to: int foo = 3; printf( "%s = %d\n", foo.symbol, foo ); // print "foo = 3" This is purely a compile time operation, generating string representations only on demand.I might be missing something, but what is the advantage over: printf( "%s = %d\n", "foo", foo ); // print "foo = 3"
May 19 2002
Walter wrote:"Russell Borogove" <kaleja estarcion.com> wrote in message news:3CE82DF2.70608 estarcion.com...I suppose you could write a generic debug function i.e. void debug(int var) { printf("%s = %d\n", var.symbol, var); } debug(foo); There are probably a lot of other uses, I agree that it doesn't look too helpful at first, but there are probably lots of other tricks you could do with it. (Just as long as it's read only!!) -JonThe property .symbol produces a text string corresponding to the identifier it's applied to: int foo = 3; printf( "%s = %d\n", foo.symbol, foo ); // print "foo = 3" This is purely a compile time operation, generating string representations only on demand.I might be missing something, but what is the advantage over: printf( "%s = %d\n", "foo", foo ); // print "foo = 3"
May 20 2002
"Jonathan Andrew" <jon ece.arizona.edu> wrote in message news:3CE921D7.CE5E4334 ece.arizona.edu...I suppose you could write a generic debug function i.e. void debug(int var) { printf("%s = %d\n", var.symbol, var); } debug(foo);Being resolved at compile time, it'd write "var = 666" (since var.symbol would probably give "var").
May 20 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:acbj3h$1263$1 digitaldaemon.com..."Jonathan Andrew" <jon ece.arizona.edu> wrote in message news:3CE921D7.CE5E4334 ece.arizona.edu...class Foo { int i; } class Bar: public Foo { } Foo obj = new Bar; obj.i = 3; printf( "%s == %d\n", obj.symbol, obj.i); // prints "Bar == 3" So maybe slightly more helpfull than you might think at first... -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mailI suppose you could write a generic debug function i.e. void debug(int var) { printf("%s = %d\n", var.symbol, var); } debug(foo);Being resolved at compile time, it'd write "var = 666" (since var.symbol would probably give "var").
May 20 2002
"OddesE" <OddesE_XYZ hotmail.com> wrote in news:acboqg$17gb$1 digitaldaemon.com:"Pavel Minayev" <evilone omen.ru> wrote in message news:acbj3h$1263$1 digitaldaemon.com...obj.classinfo.name"Jonathan Andrew" <jon ece.arizona.edu> wrote in messageFoo obj = new Bar; obj.i = 3; printf( "%s == %d\n", obj.symbol, obj.i); // prints "Bar == 3"
May 20 2002
"OddesE" <OddesE_XYZ hotmail.com> wrote in message news:acboqg$17gb$1 digitaldaemon.com...class Foo { int i; } class Bar: public Foo { } Foo obj = new Bar; obj.i = 3; printf( "%s == %d\n", obj.symbol, obj.i); // prints "Bar == 3"Actually, it'd print "obj" (it's the name of the _symbol_, and not its type). For typename, use classinfo.name.
May 20 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:accfor$1rop$1 digitaldaemon.com..."OddesE" <OddesE_XYZ hotmail.com> wrote in message news:acboqg$17gb$1 digitaldaemon.com...You are right ofcourse! Sorry I was confused. -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mailclass Foo { int i; } class Bar: public Foo { } Foo obj = new Bar; obj.i = 3; printf( "%s == %d\n", obj.symbol, obj.i); // prints "Bar == 3"Actually, it'd print "obj" (it's the name of the _symbol_, and not its type). For typename, use classinfo.name.
May 21 2002
So does obj.symbol give its type name, or its value's name? Variable name or type name? Or perhaps both i.e. "Bar[]* foo" Sean "OddesE" <OddesE_XYZ hotmail.com> wrote in message news:acboqg$17gb$1 digitaldaemon.com..."Pavel Minayev" <evilone omen.ru> wrote in message news:acbj3h$1263$1 digitaldaemon.com..."Jonathan Andrew" <jon ece.arizona.edu> wrote in message news:3CE921D7.CE5E4334 ece.arizona.edu...class Foo { int i; } class Bar: public Foo { } Foo obj = new Bar; obj.i = 3; printf( "%s == %d\n", obj.symbol, obj.i); // prints "Bar == 3" So maybe slightly more helpfull than you might think at first...I suppose you could write a generic debug function i.e. void debug(int var) { printf("%s = %d\n", var.symbol, var); } debug(foo);Being resolved at compile time, it'd write "var = 666" (since var.symbol would probably give "var").
May 21 2002
Pavel Minayev wrote:"Jonathan Andrew" <jon ece.arizona.edu> wrote in message news:3CE921D7.CE5E4334 ece.arizona.edu...Hmm, good point. -JonI suppose you could write a generic debug function i.e. void debug(int var) { printf("%s = %d\n", var.symbol, var); } debug(foo);Being resolved at compile time, it'd write "var = 666" (since var.symbol would probably give "var").
May 21 2002