www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Feature: __FUNCTION__ to give name of parent function.

reply Iain Buclaw <ibuclaw ubuntu.com> writes:
This was a question asked in IRC, someone wanting a way to have the parent
function
name outputted for logging purposes. Just like there is __LINE__ and __FILE__
for
access to the line number and filename, would be handy (and trivial to
implement)
if there was a __FUNCTION__ variable also for outputting the bare name of the
function. Optionally could also add a __PRETTY_FUNCTION__ too for outputting the
type signature of the function.

ie:
writeln(__FUNCTION__); // foo
writeln(__PRETTY_FUNCTION__); // int foo(string)

Regards
Dec 21 2010
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Iain Buclaw:

 someone wanting a way to have the parent function
 name outputted for logging purposes. Just like there is __LINE__ and __FILE__
for
 access to the line number and filename, would be handy (and trivial to
implement)
 if there was a __FUNCTION__ variable also for outputting the bare name of the
 function.

I have seen this enhancement request many times. Time ago I have also suggested a reference to the function itself, to be used in self recursive functions. Bye, bearophile
Dec 21 2010
prev sibling next sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 12/21/10 10:20 AM, Iain Buclaw wrote:
 This was a question asked in IRC, someone wanting a way to have the parent
function
 name outputted for logging purposes. Just like there is __LINE__ and __FILE__
for
 access to the line number and filename, would be handy (and trivial to
implement)
 if there was a __FUNCTION__ variable also for outputting the bare name of the
 function. Optionally could also add a __PRETTY_FUNCTION__ too for outputting
the
 type signature of the function.

 ie:
 writeln(__FUNCTION__); // foo
 writeln(__PRETTY_FUNCTION__); // int foo(string)

 Regards

Yah, we need such. To help with generic code, I'm hoping for: function.stringof module.stringof class.stringof struct.stringof union.stringof enum.stringof to yield the name of the current entity. Andrei
Dec 21 2010
parent "Nick Sabalausky" <a a.a> writes:
"Andrei Alexandrescu" <SeeWebsiteForEmail erdani.org> wrote in message 
news:iequlo$rdb$2 digitalmars.com...
 On 12/21/10 10:20 AM, Iain Buclaw wrote:
 This was a question asked in IRC, someone wanting a way to have the 
 parent function
 name outputted for logging purposes. Just like there is __LINE__ and 
 __FILE__ for
 access to the line number and filename, would be handy (and trivial to 
 implement)
 if there was a __FUNCTION__ variable also for outputting the bare name of 
 the
 function. Optionally could also add a __PRETTY_FUNCTION__ too for 
 outputting the
 type signature of the function.

 ie:
 writeln(__FUNCTION__); // foo
 writeln(__PRETTY_FUNCTION__); // int foo(string)

 Regards

Yah, we need such. To help with generic code, I'm hoping for: function.stringof module.stringof class.stringof struct.stringof union.stringof enum.stringof to yield the name of the current entity.

Yea, I don't even care what the syntax for it is; it's such a frequent request, there should at least be some way to invoke it.
Dec 21 2010
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Tuesday, December 21, 2010 08:20:06 Iain Buclaw wrote:
 This was a question asked in IRC, someone wanting a way to have the parent
 function name outputted for logging purposes. Just like there is __LINE__
 and __FILE__ for access to the line number and filename, would be handy
 (and trivial to implement) if there was a __FUNCTION__ variable also for
 outputting the bare name of the function. Optionally could also add a
 __PRETTY_FUNCTION__ too for outputting the type signature of the function.
 
 ie:
 writeln(__FUNCTION__); // foo
 writeln(__PRETTY_FUNCTION__); // int foo(string)
 
 Regards

__FUNCTION__ exists in C++. I added a feature request for it a couple of months ago: http://d.puremagic.com/issues/show_bug.cgi?id=5140
Dec 21 2010