Forum > General
is there a way of obtaining a function or procedure name string from FPC ?
440bx:
Hello,
The C++ 11 standard defines a macro __func__ which yields the name of the enclosing function as a null terminated character string. Using Pascal as an example, it does the following:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function myfunction(parameters here) : returntypehere;begin writeln('Currently executing', __func__);end;
would output: "Currently executing myfunction"
does FPC have a way of getting the name of the function (myfunction in this case, i.e, __func__ equivalent) ?
This is particularly convenient when outputting error messages, spares the programmer from having to type (and possibly misspell) the name of the function in error messages and any other messages where the function name would be useful information to have.
Thank you for your help
ASerge:
Only in future version. In trunk this work:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1;{$APPTYPE CONSOLE}{$MODE OBJFPC} procedure SomeName;begin Writeln('Name is ', {$I %CURRENTROUTINE%});end; procedure OtherName;begin Writeln('Name is ', {$I %CURRENTROUTINE%});end; begin SomeName; OtherName; Readln;end.
howardpc:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$I %CURRENTROUTINE%}works in FPC 3.1.1
440bx:
Thank you for the replies, they are good news.
I am looking forward the next stable release of FPC that includes this feature. It's quite convenient for error messages.
Now, I'm really curious, anyone have any idea when the next stable release that includes this feature might be coming out ?
marcov:
--- Quote from: 440bx on July 06, 2018, 05:29:28 pm ---Now, I'm really curious, anyone have any idea when the next stable release that includes this feature might be coming out ?
--- End quote ---
Release process hasn't started yet, so minimum 6-9 months.
Navigation
[0] Message Index
[#] Next page