Recent

Author Topic: How to check if function or procedure is actually doing something  (Read 449 times)

vask0to

  • Newbie
  • Posts: 1
Lets say I have this procedure which contains only comment and no executable code in its body.
Code: Pascal  [Select][+][-]
  1.    procedure Procedure1
  2.    begin
  3.    //comment
  4.    end;
Is there a way to call this function and verify wheter it does something or doesn't actually do anything?
And also the same for a function.

Thaddy

  • Hero Member
  • *****
  • Posts: 10295
Re: How to check if function or procedure is actually doing something
« Reply #1 on: July 06, 2020, 02:55:52 pm »
You can examine the assembler output.
You will find that depending on optimization settings it does nothing because the compiler can remove such code.
I am more like donkey than shrek

Blaazen

  • Hero Member
  • *****
  • Posts: 2853
  • POKE 54296,15
    • Eye-Candy Controls
Re: How to check if function or procedure is actually doing something
« Reply #2 on: July 06, 2020, 03:32:47 pm »
There's
  Refactoring -> Empty methods ...
but the methods must be really empty, i.e. no comment.
Lazarus 2.1.0 r63594 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jamie

  • Hero Member
  • *****
  • Posts: 3277
Re: How to check if function or procedure is actually doing something
« Reply #3 on: July 06, 2020, 04:43:42 pm »
I like using BEEPS...  :D

Put a BEEP in there.. and it will sound your speakers if it gets executed
The only true wisdom is knowing you know nothing

trev

  • Hero Member
  • *****
  • Posts: 843
  • Former Delphi 1-7 and 10.2 User
Re: How to check if function or procedure is actually doing something
« Reply #4 on: July 07, 2020, 05:18:44 am »
Beware the warning in the FPC documentation: "Beep contains no implementation to actually produce a beep, since there is no way to implement beep in a meaningful way for all possible implementations."

I discovered that, for example, in macOS and FreeBSD it does nothing.
o Lazarus v2.1.0 r63598, FPC v3.3.1 r45778, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (Parallels VM)
o FPC 3.0.4, FreeBSD 12-STABLE r361007 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

jamie

  • Hero Member
  • *****
  • Posts: 3277
Re: How to check if function or procedure is actually doing something
« Reply #5 on: July 07, 2020, 03:31:04 pm »
Use a break point then. If it jumps to that block it will stop there and prompt u.
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 10295
Re: How to check if function or procedure is actually doing something
« Reply #6 on: July 07, 2020, 03:34:20 pm »
There's
  Refactoring -> Empty methods ...
but the methods must be really empty, i.e. no comment.
No. depending on optimization no code is no code to the compiler. It is just the Lazarus ide that keeps the comment in place for the project, but not for the compiler....
There is a big difference. You can check that by examining the assembler output.
« Last Edit: July 07, 2020, 03:37:13 pm by Thaddy »
I am more like donkey than shrek

 

TinyPortal © 2005-2018