Lazarus

Free Pascal => Beginners => Topic started by: vask0to on July 06, 2020, 02:46:09 pm

Title: How to check if function or procedure is actually doing something
Post by: vask0to on July 06, 2020, 02:46:09 pm
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.
Title: Re: How to check if function or procedure is actually doing something
Post by: Thaddy 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.
Title: Re: How to check if function or procedure is actually doing something
Post by: Blaazen on July 06, 2020, 03:32:47 pm
There's
  Refactoring -> Empty methods ...
but the methods must be really empty, i.e. no comment.
Title: Re: How to check if function or procedure is actually doing something
Post by: jamie 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
Title: Re: How to check if function or procedure is actually doing something
Post by: trev 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.
Title: Re: How to check if function or procedure is actually doing something
Post by: jamie 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.
Title: Re: How to check if function or procedure is actually doing something
Post by: Thaddy 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.
TinyPortal © 2005-2018