Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29235 Discussions

Unused Variable Warning - Disable for one instance?

holysword
Novice
2,590 Views
Hi there,
Is there any way to disable the "unused variable" warning for one specific occurrence of an unused variable in ifort?
The reason why I am asking that is the following; I have several classes which implement, in a different way, an abstract function defined somewhere in a parent class, let us say, myfunc_abstract(a,b,c). However, some implementations use all the three variables, some use two of them only - and I cannot remove the dummy argument because the interface has to be the same as defined in the abstract interface declaration.
Honestly, I don't think the compiler should throw the "unused variable" warning in these situations; is there a compiler option or preprocessor trick to avoid that?
I am using ifort 12.1.5 20120612.
1 Solution
Steven_L_Intel1
Employee
2,590 Views
It does not really know that it is implementing a deferred procedure, and there's nothing preventing the routine from being called independently. However, we support an old Microsoft trick - a "do nothing" routine called UNUSEDQQ. So you could do something like:

use ifcore
...
if (.false.) call unusedqq(notused)

You have to do a USE IFCORE to make it visible. The if (.false.) will prevent the call from actually getting generated.

View solution in original post

0 Kudos
3 Replies
Steven_L_Intel1
Employee
2,590 Views
The classic way is to put:

b = b

in the routime somewhere. The compiler would eventually optimize this away. How is the compiler supposed to know you didn't intend to use the dummy argument?
0 Kudos
holysword
Novice
2,590 Views
As it is an INTENT(IN) variable only I cannot really do that, but I surelly can do other spurious usages.
The compiler knows that this routine is implementing a deferred procedure for sure; as so, it should know that I am forced to let the dummy argument there, regardless if I use it or not.
Thank you
0 Kudos
Steven_L_Intel1
Employee
2,591 Views
It does not really know that it is implementing a deferred procedure, and there's nothing preventing the routine from being called independently. However, we support an old Microsoft trick - a "do nothing" routine called UNUSEDQQ. So you could do something like:

use ifcore
...
if (.false.) call unusedqq(notused)

You have to do a USE IFCORE to make it visible. The if (.false.) will prevent the call from actually getting generated.
0 Kudos
Reply