This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Is is possible to use the name of a variable in the constructor?
- From: Gunther Piez <gpiez at web dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 1 Aug 2005 02:32:22 +0200
- Subject: Re: Is is possible to use the name of a variable in the constructor?
- References: <200508010155.53152.gpiez@web.de> <m3wtn61q18.fsf@gossamer.airs.com>
Am Montag, 1. August 2005 02:04 schrieb Ian Lance Taylor:
> Gunther Piez <gpiez@web.de> writes:
> > struct uniform {
> > uniform() {
> > cout << "A variable called " << __PRETTY_VARNAME__ << " was just
> > instantinated (sp)" << endl;
> > }
> > };
>
> Remember that in general uniform::uniform may be in different source
> file, and may be compiled before the function which uses a variable of
> type uniform. The only way this could be made to work would be to
> have the compiler secretly pass the variable name into the function.
> There is no infrastructure for noting which functions would require
> the variable name, or for passing in the variable name.
Ok, I understand the difference to __PRETTY_FUNCTION__ now :-)
Maybe it is possible to use the debugging information somehow? At least the
debugger usually knows the names of variables. Otherwise I have to use a
constructor like
uniform::uniform(const char*);
and declare variables like
uniform blah("blah");
which is ugly.