Unused variables in Fortran programs

Steve Kargl sgk@troutmask.apl.washington.edu
Mon Jan 3 21:11:00 GMT 2005


On Mon, Jan 03, 2005 at 09:41:32PM +0100, Erik Schnetter wrote:
> 
> There are two kinds of unused variables.  Some are already in common 
> blocks (and there is a feature request to gfortran to not warn about 
> these), but others are actually routine arguments, as in
> 
>  subroutine a(x, y)
>    implicit none
>    integer x
>    integer y
>  end subroutine a
> 
> where the list of arguments is partly automatically generated (through 
> cpp macros), and where some of the variables may not be used.  I would 
> like to avoid only those warnings about those arguments that are 
> automatically generated.
> 

Have all automatically generated variables written to a file
such that each line contains for example "y = y".  Then use
the INCLUDE statement to include the contents of the file.
The "unused" variables are no longer unused, but any decent
compiler will eliminate the "y = y" lines.

program b
  x = 1
  y = 2
  call a(x,y)
end program b
 
subroutine a(x, y)
   implicit none
   integer x  
   integer y
   include 'unused'
   print *, x
end subroutine a

-- 
Steve



More information about the Fortran mailing list