-Wunused and argument lists
Richard E Maine
Richard.Maine@nasa.gov
Tue Oct 4 20:04:00 GMT 2005
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.
While I applaud the goal of getting warning-free compilation,
single-minded pusuit of that goal can be counter-productive. The fact
of the matter here seems to be that the code in question is valid. And
there are perfectly sound reasons for having unused dummy arguments in
some codes. Because of that, it can be handy to have an option to
disable unused testing for dummy arguments (even if you still have
unused testing for other things).
Oh, of you don't understand why you might have just turned the code
invalid with this change, consider
1. The possibility that b is undefined, making it nonstandard to
reference it. Although it will usually be harmless, it does violate the
standard and there do exist compilers that can check things like this.
2. Suppose the actual argument for b is a literal constant. In this
case, it is quite likely that you'll get a crash during execution.
--
Richard Maine | Good judgment comes from experience;
Richard.Maine@nasa.gov | experience comes from bad judgment.
| -- Mark Twain
More information about the Fortran
mailing list