6

What is the best practice in Fortran to suppress warning messages like:

remark #7712: This variable has not been used.

for just one particular variable (imagine function in API that we do not want to break)?

Note: I do not want to suppress all warnings for a file

Note2: Something similar for gcc: __attribute__((__unused__)) or other common C practice with MACRO

Note3: I am particularly interested in ifort, but multi-compiler would be better.

albert
  • 8,285
  • 3
  • 19
  • 32
Peter Petrik
  • 9,701
  • 5
  • 41
  • 65
  • why not just remove it? or do some simple operation to use it (thats all that c macro does) – agentp Jul 02 '14 at 13:29
  • @george Usually you do not remove the variable from function that is exposed via public API. It breaks backward compatibility. The question is what is the best practice, so which operation to use/how to supress it? – Peter Petrik Jul 02 '14 at 13:33
  • I don't know about best practice, but my current practice is, and has for a long time been, to ignore the warning. Only justification for this is that, if you modify (say) your build process to mask the warning you run the risk that in future you, well, mask the warning when you no longer ought to. – High Performance Mark Jul 02 '14 at 14:30
  • 4
    Unfortunately lots of warnings make developers ignore them all... – Peter Petrik Jul 02 '14 at 14:48

1 Answers1

4

Since you're using Intel Fortran (I can tell from the particular message), you have a couple of options. One is to add a dummy reference, for example:

if (.false.) unused=1

Another is to disable just unused variable warnings:

/warn:all,nounused

or for Linux:

-warn all,nounused

Microsoft Fortran had an interesting library function UNUSEDQQ for this purpose - you added a call to UNUSEDQQ passing the variable, and this disabled the check. Intel Fortran doesn't support that.

Steve Lionel
  • 6,972
  • 18
  • 31