Silverfrost Forums

Welcome to our forums

Unused subroutines and functions

21 Jun 2011 1:38 #8440

Hi,

A quick question.

Over the years our application has acquired routines that I'm sure are no longer being used, but daren't just delete them! Is there a link switch that can list any un-called functions?

K

21 Jun 2011 2:51 #8441

Kenny,

If you suspect a particular routine may not be called anywhere, then you could use the DOS command FIND to search through all your source code files for the name of the routine. This will list the subroutine itself plus any calls if they exist.

Cheers, John

21 Jun 2011 3:46 #8442

What you need is the opposite of the SLINK switch /lure but I cannot find anything like it.

Plato has a 'Find in Files' command that may be useful.

21 Jun 2011 3:50 #8443

I have a suspicion that SLINK doesn't link any routines that aren't called, so even if they appear in your source code, they don't make it (as dead code) into the EXE. So, if you can bear the (often negligible) overhead of recompiling them, then everything comes right in the end.

John's suggestion is a good one. You can also search with a text editor. The problem is that sometimes the call is there, but it is never actively pursued, e.g.

      IF (KEYBOARD_MODE .EQ. 1) THEN
      CALL BRUCE_BOWLER_CODE
      ENDIF

does lead to the routine being linked, even if KEYBOARD_MODE is set to something other than 1, because that was an option you abandoned 6 years ago!

Eddie

22 Jun 2011 12:08 #8447

Bruce has an idea, You could convert most of your code into a library and then use 'le code.lib' in slink. This would then only load the routines that are called. You could then import the .map file into excel and sort it to locate routines that are called. Note:

  1. It use to be that if one routine was called from a .obj file, then all routines in the .obj file were loaded. To overcome this I created a seperate .for file for each routine then used SLINK to create the library, using 'addobj routinexx.obj' for each seperate routine. I'm not sure if this is still the case with the latest version of SLINK. I've kept the same script approach for a long time.
  2. if you use 'lo code.obj', all the routines in code.obj will be loaded, so once you force load an obsolete routine, then all routines it calls will also be loaded.

We realy need a call tree generator like FORCHK use to do for F77, providing a list of all routines that called each routine. SLINK should be able to provide this report.

Eddie's suggestion that SLINK does not load unused routines certainly was not the case with older versions of SLINK. I have not tested this recently, but I would suspect it is not that smart. SLINK could/should be a lot smarter!

John

22 Jun 2011 8:04 #8451

Thanks for all the suggestions. Thought of most of them myself already - I'd even tried some of them (but got bored)!

Perhaps I'll write something to do it at one level (ie grep for all the SUBROUTINE/FUNCTIONs, output the list to a file, then search through all my source for each item and count how many times each one occurs...) but that wouldn't capture a routine that was called from an un-called routine, so may only be of limited use...

K

11 Aug 2011 6:40 #8782

We use a tool for this. I think that you should be able to download a trial. I think that the Lahey compiler has a build in function like this - perhaps something to think about for Plato 😄

11 Aug 2011 11:09 #8783

I have my own tool for doing this (written in Fortran 😃 ). It just looks for all occurances of MODULE, SUBROUTINE, FUNCTION across multiple files, extracts the names and checks there's at least one use somewhere. (USE, CALL or Function name).

I would be happy to post this here for people to use. (will do it when I'm near to my main machine).

David.

Please login to reply.