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

allocatable array and module

yjyincj
Beginner
821 Views
I got error when the following program was compiled. But I can not figure what was wrong.
module work_array
integer :: n
real, allocatable :: work (:)
end module work_array

program main
use work_array
call sub
print*, work
end program main

subroutine sub
use work_array
implicit none
n = 2
allocate (work(n))
work (1) = 1.0
work (2) = 2.0
return
end subroutine sub
The error
Error 1 Error: A non-optional actual argument must be present when invoking a procedure with an explicit interface. C:ivf est est est.F90 8

Thanks.
0 Kudos
5 Replies
Steven_L_Intel1
Employee
821 Views
Do a Build > Rebuild Solution or delete all _MOD.mod files and try again.
0 Kudos
yjyincj
Beginner
821 Views
What's the magic thing there? It works though I have figured another way to solve this issue. I put the subprogram into the module so that the interface became explicit.
0 Kudos
Steven_L_Intel1
Employee
821 Views
The magic thing is "generated interface checking". When the compiler sees a routine that is not a module or contained procedure, it generates a specially-named module containing an interface block for that routine. In version 10.x, the module is routinename_MOD and the file names are that name plus .f90 and .mod. (This will change in a future release to reduce the chance of a conflict with a user module.)

When the compiler sees a call to a routine for which no explicit interface is available, it looks to see if there is a generated module for it, and if so, uses the interface block to perform error checking. (Note that a generated interface is NOT a substitute for providing an explicit interface when the language requires one.)

The compiler tries to be smart about the case when the called routine is later in the same source in that if it does not find a generated module, it waits until the whole source has been processed before doing the checking. The problem occurs when you compile the source, edit it to change the called routine, say, removing an argument, and then recompile. This time the compiler sees that a generated interface is available, not noticing that it would be recreated later, so it uses a stale definition.

This is controlled by the options /gen-interface and /warn:interface. Both are on by default in newly-created VS projects.
0 Kudos
yjyincj
Beginner
821 Views
where do I find options? tools>options? I don't see the /gen-interface. Thanks.
0 Kudos
Steven_L_Intel1
Employee
821 Views
Project > Properties > Fortran > Diagnostics. "Generate Interface Blocks" and "Check Routine Interfaces".

Tools > Options sets Visual Studio behavior, not Fortran compile behavior.
0 Kudos
Reply