Recent

Author Topic: unused procedures  (Read 633 times)

speter

  • Full Member
  • ***
  • Posts: 100
unused procedures
« on: November 25, 2020, 01:37:31 am »
G'Day Folks,

Is there a way to get the compiler to give hints/warnings etc on procedures/functions/methods that are not called?

I was editing a unit today (to get rid of code that had been "commented out"); when I noticed that there were a number of routines that were no longer being used...  :o

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.8 / FPC 3.0.4 / Windows 10 (64bit)

winni

  • Hero Member
  • *****
  • Posts: 2116
Re: unused procedures
« Reply #1 on: November 25, 2020, 01:53:24 am »
Hi!

This was easy before the different Pascal dialects introduced the units.

Turbo Pascal <=  3.0 was proud to announce "Procedure xyz not used".
On every compiler run.

But starting with the units it gets complicated.
Nearly every app needs sysutils.
But - for example - you just needed some DateTime operations.
Would you like to get hundreds of messages that other functions and procedures of sysutils are not used?

That would be more confusing than helpfull.

Toto - we are not at Turbo 3.0 anymore.

Winni

speter

  • Full Member
  • ***
  • Posts: 100
Re: unused procedures
« Reply #2 on: November 25, 2020, 03:05:24 am »
Winni: Fair enough. But, it would still be nice to get a hint about _my_ routines! :)

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.8 / FPC 3.0.4 / Windows 10 (64bit)

Thaddy

  • Hero Member
  • *****
  • Posts: 10684
Re: unused procedures
« Reply #3 on: November 25, 2020, 06:32:43 am »
There is an option for that but I have to look it up. The verbosity can be raised through the -v<xxx> options.
Anyway, the compiler will remove unused procedures and functions. And WPO can remove even more.
So basically, because of the above I just leave that code in my units.
[edit]
compile with -vh  or -vhl and you get the hints about unused procedures and functions.
Or turn hints on in Lazarus if it happens to be off. That should work. E.g.
Code: Bash  [Select][+][-]
  1. teststrptr.pas(3,11) Hint: Local proc "dummy" is not used
Note this option can be very verbose on large files. You can use grep to filter them out.
« Last Edit: November 25, 2020, 07:35:41 am by Thaddy »

PascalDragon

  • Hero Member
  • *****
  • Posts: 2594
  • Compiler Developer
Re: unused procedures
« Reply #4 on: November 25, 2020, 07:19:36 am »
compile with -vh  or -vhl and you get the hints about unused procedures and functions.
Or turn hints on in Lazarus if it happens to be off. That should work. E.g.
Code: Bash  [Select][+][-]
  1. teststrptr.pas(3,11) Hint: Local proc "dummy" is not used

Please note that this only applies to routines in the main program or that are only declared inside the implementation section of a unit. Routines that are part of the interface are not reported, because the unit might be used by some other program as well.

However the compiler will not link in routines (or types) that are not used at all anyway (best to compile with -CX -XX).

Thaddy

  • Hero Member
  • *****
  • Posts: 10684
Re: unused procedures
« Reply #5 on: November 25, 2020, 07:40:50 am »
Yes, of course. Forgot about that.
(I compile with -CX -XXs btw)

speter

  • Full Member
  • ***
  • Posts: 100
Re: unused procedures
« Reply #6 on: November 25, 2020, 11:41:13 am »
Thanks Folks,

I do compile using -CX -XX (and I have -vh checked); I couldn't find -vhl though.

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.8 / FPC 3.0.4 / Windows 10 (64bit)

Thaddy

  • Hero Member
  • *****
  • Posts: 10684
Re: unused procedures
« Reply #7 on: November 25, 2020, 01:11:18 pm »
@speter
with the -v switch you can concat options, so you can write -vhl instead of -vh -vl.
Same with -XXs which is the same as -XX -Xs and many more compound options like -Criot
Compound options are a powerfull shorthand
« Last Edit: November 25, 2020, 01:18:46 pm by Thaddy »

speter

  • Full Member
  • ***
  • Posts: 100
Re: unused procedures
« Reply #8 on: November 26, 2020, 12:21:16 am »
Thanks Thaddy.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.8 / FPC 3.0.4 / Windows 10 (64bit)

 

TinyPortal © 2005-2018