| Thread overview | |||||
|---|---|---|---|---|---|
|
December 20, 2017 Is there a way to get a function name within a function? | ||||
|---|---|---|---|---|
| ||||
Greetings!
Imagine,
//start
int getMe(int i)
{
writefln(__LINE__);
writefln(__FUNCTION_NAME__);
return I + 1;
}
void main(args )
{
getMe(1);
}
//end
So, the result would be,
4
getMe
So, is there a way to get the name of the function while in that function? I know I can use some debugging and hard code it, but I would like to use it.
thanks.
| ||||
December 20, 2017 Re: Is there a way to get a function name within a function? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to jicman | On Wednesday, 20 December 2017 at 23:28:46 UTC, jicman wrote: > Greetings! > > Imagine, > > //start > int getMe(int i) > { > writefln(__LINE__); > writefln(__FUNCTION_NAME__); So close! Use "__FUNCTION__" or "__PRETTY_FUNCTION__". https://dlang.org/spec/traits.html#specialkeywords -Johan | |||
December 21, 2017 Re: Is there a way to get a function name within a function? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Johan Engelen | On Wednesday, 20 December 2017 at 23:51:29 UTC, Johan Engelen wrote:
> On Wednesday, 20 December 2017 at 23:28:46 UTC, jicman wrote:
>> Greetings!
>>
>> Imagine,
>>
>> //start
>> int getMe(int i)
>> {
>> writefln(__LINE__);
>> writefln(__FUNCTION_NAME__);
>
> So close! Use "__FUNCTION__" or "__PRETTY_FUNCTION__".
> https://dlang.org/spec/traits.html#specialkeywords
>
> -Johan
Thanks, Johan.
josé
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply