This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Is is possible to use the name of a variable in the constructor?


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]