* * *

Author Topic: is there a way of obtaining a function or procedure name string from FPC ?  (Read 1147 times)

440bx

  • Sr. Member
  • ****
  • Posts: 336
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  [Select]
  1. function myfunction(parameters here) : returntypehere;
  2. begin
  3.    writeln('Currently executing', __func__);
  4. 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

« Last Edit: July 06, 2018, 05:33:23 am by 440bx »

ASerge

  • Hero Member
  • *****
  • Posts: 965
Only in future version. In trunk this work:
Code: Pascal  [Select]
  1. program Project1;
  2. {$APPTYPE CONSOLE}
  3. {$MODE OBJFPC}
  4.  
  5. procedure SomeName;
  6. begin
  7.   Writeln('Name is ', {$I %CURRENTROUTINE%});
  8. end;
  9.  
  10. procedure OtherName;
  11. begin
  12.   Writeln('Name is ', {$I %CURRENTROUTINE%});
  13. end;
  14.  
  15. begin
  16.   SomeName;
  17.   OtherName;
  18.   Readln;
  19. end.

howardpc

  • Hero Member
  • *****
  • Posts: 2806
Code: Pascal  [Select]
  1. {$I %CURRENTROUTINE%}
works in FPC 3.1.1

440bx

  • Sr. Member
  • ****
  • Posts: 336
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6582
Now, I'm really curious, anyone have any idea when the next stable release that includes this feature might be coming out ?

Release process hasn't started yet, so minimum 6-9 months.

440bx

  • Sr. Member
  • ****
  • Posts: 336
Release process hasn't started yet, so minimum 6-9 months.

6 months would be great, it would make for a nice Xmas present. :)  Thank you for the update.

engkin

  • Hero Member
  • *****
  • Posts: 2116
Release process hasn't started yet, so minimum 6-9 months.

6 months would be great, it would make for a nice Xmas present. :)

I thought you already had one.  :D

440bx

  • Sr. Member
  • ****
  • Posts: 336
Release process hasn't started yet, so minimum 6-9 months.

6 months would be great, it would make for a nice Xmas present. :)

I thought you already had one.  :D

yeah, I did... you gave me one already but... you know kids, they always want more ;)

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus