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

Check for forgotten use statements

Danny_L_
Beginner
382 Views

Hello, 

I am debugging a code that mysteriously fails on me. The code uses a lot of use statements to make things modular. How can I check whether I forgot to put such a USE stament in one of the calling routines? The compiler will resolve these calls during linking with the result that the interface is probably no good with strange things happening. The Warn interfaces (or all) option does not seem to tell me anything (also not sure what it does exactly). Is there a way to be sure that no USE statements are missing? Thank you. Danny.

 

 

 

 

 

0 Kudos
6 Replies
mecej4
Honored Contributor III
382 Views

There is no direct requirement for USE statements in Fortran source. There are cases where an interface is required (the implicit interface is faulty), and one way to provide an interface is through a USE statement.

Code can fail for many different reasons, and the implicit interface being incorrect is just one of those.  Please provide more details about why you think the code failed, and what evidence (error messages, traceback, etc.) you have that it failed.

If you can provide a complete example code and instructions to reproduce the failure, so much the better.

0 Kudos
Steven_L_Intel1
Employee
382 Views

-warn interface generates a pseudo-module with interface block for any external procedures (not already in a module) in your program. These are then checked when you make a call to a procedure where no explicit interface exists to make sure they match. I highly recommend its use.

If the procedure you are calling is in a module, then a call without a USE for that module won't link. If you have a module that provides interface blocks for external procedures, then there's no option that will help you (other than -warn interface will usually complain if there's a mismatch, but it needs the called procedure to be compiled first to work.)

Fortran 2015 will have a new "IMPLICIT NONE (EXTERNAL)" statement that will require all procedure references to have an explicit interface visible. Intel Fortran doesn't have that yet.

0 Kudos
IanH
Honored Contributor II
382 Views

Steve Lionel (Intel) wrote:
Fortran 2015 will have a new "IMPLICIT NONE (EXTERNAL)" statement that will require all procedure references to have an explicit interface visible.
I think the proposed semantics of that statement just requires procedure names to have the external attribute, not a "full" explicit interface.

 

0 Kudos
Steven_L_Intel1
Employee
382 Views

Well, yes, it has to be declared EXTERNAL or have an explicit interface. 

0 Kudos
Danny_L_
Beginner
382 Views

Thank you all for your comments. I did some cleaning and was not able to reproduce what happened earlier (seemed like code was stuck in a loop or so). Code is now acting normally. To be continued possibly later.

I tested what Steve Lionel wrote (will not link when not use'd). Indeed this is the case (pretty smart compiler). This means that a use statement in principle can never be forgotten wo leading to a compiler error. 

My supposition that the error may had something to do with interfaces was based on previous debug experiences (with Intel v11) with external subroutines that required an explicit interface block for the code to work properly (If I remember well the v11 compiler was fine with omitting the block but at some point you crash and weird things happen).

Thanks.

0 Kudos
Steven_L_Intel1
Employee
382 Views

More likely you had some procedures for which the language requires an explicit interface, but if one was not supplied the results were unpredictable. In the absence of an interface, the compiler assumes Fortran-77 style argument passing and this won't be right if the called procedure has such things as assumed-shape arrays, optional arguments, etc. I wrote about this here.

0 Kudos
Reply