Is there a way to get the name of the current function?

rempas rempas at tutanota.com
Wed Mar 8 07:02:46 UTC 2023


On Tuesday, 7 March 2023 at 22:28:41 UTC, ryuukk_ wrote:
>
>
> ```
> import std.stdio;
> void main()
> {
>     writeln("file:        ", __FILE__);
>     writeln("function is: ", __FUNCTION__);
>     writeln("function is: ", __PRETTY_FUNCTION__ );
> }
>
> $ dmd -run tester.d
> file:        tester.d
> function is: tester.main
> function is: void tester.main()
> ```
>
> You can even get the calling function name:
>
> ```
> import std.stdio;
> void main()
> {
>     log("hello");
> }
>
>
> void log(string msg, string file = __FILE__, int line = 
> __LINE__, string fn = __PRETTY_FUNCTION__)
> {
>     writeln(file,":",line,"|", fn,"|> ", msg);
> }
> ```
>
> https://dlang.org/spec/expression.html#specialkeywords

Thanks a lot for the detailed examples! Have an amazing day!


More information about the Digitalmars-d-learn mailing list