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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gunther Piez <gpiez@xxxxxx> writes:

> I'm looking for something like __PRETTY_FUNCTION__ for a variable (or a 
> object).
> It want to do
> 
> struct uniform {
> 	uniform() {
> 		cout << "A variable called " << __PRETTY_VARNAME__ << " was just 
> instantinated (sp)" << endl;
> 	}
> };
> 
> void main() {
> 	uniform blah;
> }
> 
> 
> and get "A variable called blah was just instantinated" as program output. 
> This must work at runtime. Is there a identifier or macro which holds the 
> desired value?

No.

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.

It would be possible to make this work in very specific cases, but I
don't think this type of language extension would be very interesting
if it couldn't work in the general case.

Ian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux