Unused variables in Fortran programs
Gordon Sande
g.sande@worldnet.att.net
Mon Jan 3 21:15:00 GMT 2005
Erik Schnetter wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Monday 03 January 2005 21:24, Gordon Sande wrote:
>
>>Erik Schnetter wrote:
>>
>>>-----BEGIN PGP SIGNED MESSAGE-----
>>>Hash: SHA1
>>>
>>>Is there a way to make gfortran not warn about certain unused
>>>variables when -Wunused is used? I am looking for the equivalent
>>>of __attribute__((unused)) for some automatically generated parts
>>>of Fortran code.
>>>
>>>Do you know how other Fortran compilers do this? Do they maybe
>>>offer some special comments, as in
>>>
>>> integer i
>>> ! unused i
>>
>>You could always try
>>
>> common / otherwise_unused_vars / i
>> integer i
>>
>>depending on how effective the checking is. A useful variant would be
>>that if NO variable in the common is used then the common should get
>>the citation for being unused. That would make this trick useless as
>>it is just exploiting a flaw in the usage analysis.
>
>
> 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.
I tend to think of three types:
1. Unused arguments. Often because the argument list is specified
elsewhere. These generate warnings that it would be nice to eliminate
as you suggest. A NO_OP intrinsic to provide a use. Or perhaps an
INTENT ( UNUSED ) to go with IN, OUT and INOUT.
2. Placeholders in a common (or module). These are not diagnosed because
they are required but if the common has ONLY placeholders then the
common is unused. Often there is no diagnostic when it would be
useful. In simple program preprocessors such as one might see in
simulations there are often a small set of declared variables that
might not be used which then generate a large number of warnings
which can "hide" real diagnostics. My trick is a poor stop gap for
this sort of problem, and the trick would not work if the analysis
was as good as I would like.
3. The real unused variables. They stop being used and one likes the
reminder to clean things up.
> - -erik
>
> - --
> Erik Schnetter <schnetter@aei.mpg.de> http://www.aei.mpg.de/~eschnett/
>
> My email is as private as my paper mail. I therefore support encrypting
> and signing email messages. Get my PGP key from www.keyserver.net.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.4 (GNU/Linux)
>
> iD8DBQFB2a38m3uiSwno3f0RAqmZAJ4j2SVcuoyX0fFKnkSW1WKprkS8xACgyV2v
> aVlFHbVDvzPCgINGmvfXSII=
> =PKL0
> -----END PGP SIGNATURE-----
>
>
More information about the Fortran
mailing list