Recent

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

440bx

  • Hero Member
  • *****
  • Posts: 3946
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 »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

ASerge

  • Hero Member
  • *****
  • Posts: 2223
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: 4144
Code: Pascal  [Select][+][-]
  1. {$I %CURRENTROUTINE%}
works in FPC 3.1.1

440bx

  • Hero Member
  • *****
  • Posts: 3946
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 ?
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
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

  • Hero Member
  • *****
  • Posts: 3946
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.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

engkin

  • Hero Member
  • *****
  • Posts: 3112
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

  • Hero Member
  • *****
  • Posts: 3946
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 ;)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018