D - Yet another property idea
- Russell Borogove <kaleja estarcion.com> May 19 2002
- "Walter" <walter digitalmars.com> May 19 2002
- Jonathan Andrew <jon ece.arizona.edu> May 20 2002
- "Pavel Minayev" <evilone omen.ru> May 20 2002
- "OddesE" <OddesE_XYZ hotmail.com> May 20 2002
- Patrick Down <pat codemoon.com> May 20 2002
- "Pavel Minayev" <evilone omen.ru> May 20 2002
- "OddesE" <OddesE_XYZ hotmail.com> May 21 2002
- "Sean L. Palmer" <seanpalmer earthlink.net> May 21 2002
- Jonathan Andrew <jon ece.arizona.edu> May 21 2002
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...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"
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!!) -Jon
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...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").
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 mail
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..."Jonathan Andrew" <jon ece.arizona.edu> wrote in message
Foo obj = new Bar; obj.i = 3; printf( "%s == %d\n", obj.symbol, obj.i); // prints "Bar == 3"
obj.classinfo.name
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...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.
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 mail
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...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").
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...
May 21 2002
Pavel Minayev wrote:"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").
Hmm, good point. -Jon
May 21 2002









Patrick Down <pat codemoon.com> 