Recent

Author Topic: How to check if function or procedure is actually doing something  (Read 726 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: 10782
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.

Blaazen

  • Hero Member
  • *****
  • Posts: 3034
  • 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 r64546 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: 4441
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1424
  • Former Delphi 1-7, 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.
Lazarus 2.1 r65061 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r65070 FPC 3.3.1 r49223 macOS 11.2.3 aarch64 Xcode 12.4
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

jamie

  • Hero Member
  • *****
  • Posts: 4441
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: 10782
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 »

 

TinyPortal © 2005-2018