-Wunused and argument lists

David C. Thompson dcthomp@sandia.gov
Tue Oct 4 21:14:00 GMT 2005


On Tue, 2005-10-04 at 12:58, Richard E Maine wrote:
> On Oct 4, 2005, at 12:43 PM, Andrew Pinski wrote:
> >> 	I'm trying to get warning-free compiles of some old F77 code using
> >> gfortran (a gcc compiled from CVS at hpc.sourceforge.net, dated Sep.
> >> '05), but I am having trouble with -Wunused; I have some functions 
> >> where
> >> not all the arguments are used, but those arguments must still be 
> >> passed
> >> because a library requires the argument list as given. For example:
> >>
> >>        REAL*8 FUNCTION f(a,b)
> >>        IMPLICIT NONE
> >>        INTEGER*4 a,b
> >>        F = 7.7d1*a
> >>        END
> >>
> >> will get a warning about "b" being unused, but I am not free to remove
> >> "b" from the argument list. In C, I would just use
> >
> > what about this trickery:
> > b = b
> 
> I tend to recommend against "trickery" like that. It is often 
> counter-productive. In this case, for example, you might well have just 
> managed to change code that was standard-conforming code, even though 
> it generates warnings, into something that is not standard-conforming 
> and might well crash in execution. Doesn't sound like a very good 
> tradeoff to me.
That is exactly why I am asking the people on this list rather than
trying to develop tricks of my own. :-) While Steve Kargl noted I could
turn off the warnings, I would like to catch unused variables (just not
unused arguments). I like Andrew Pinski's trick and don't think it will
cause any trouble for this particular code -- or rather, if it does, it
will be much easier to debug than subtle or conceptual errors that
unused variables tend to indicate. The problem I have with just leaving
the warnings is that there are enough of them that I have trouble
spotting the real warnings among the ones that should be ignored.

I also wanted to make sure that this wasn't some problem with gfortran.
It seems that good old g77 doesn't report unused arguments but does
report unused local variables, and I am curious whether the additional
warnings exist for a reason or are an unintended product of compiler
development.

	Thanks for all of your input,
	David

-- 
David Thompson, MS 9152                (925)294-2537
Sandia National Laboratories           dcthomp@sandia.gov
Distributed Visualization Systems 8963 Bldg/Rm 915/N144
PO Box 969, Livermore, CA 94551-0969



More information about the Fortran mailing list