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

Optional my foot

rahzan
New Contributor I
994 Views
The following call produces the warning:
...no actual arg corresponding to dummy arg N...

any ideas?


call stopit('Hello')
...
subroutine Stopit(msg,n)
integer,optional ,intent(in):: n
character(111),intent(in):: msg
0 Kudos
8 Replies
Steven_L_Intel1
Employee
994 Views
You need an explicit interface to call a routine with an optional argument.

Steve
0 Kudos
james1
Beginner
994 Views
Try adding a comma immediately after 'Hello'.

James
0 Kudos
llynisa
Beginner
994 Views
But Steve, I have been happily using optional arguments without explicit interfaces by putting the subroutines with optional arguments into a module. I learnt this from you, after studying your very useful FortranWinPrint, which does not use an explicit interface.

Well, I was happy until recently when I have consistently been getting a warning message on compiling, which I have reduced to the simplistic case below:

Warning: In the call to UTILS_mp_CALLED, actual argument #4 has no corresponding dummy argument.
10 call Called(*10,'F')

Firstly there are only 3 arguments, and secondly it looks legal code to me. It does also link and run without any errors that I have been able to detect. I am using CVF6.6A, W2K SP3. Is it possible to get rid of this spurious warning?
MODULE UTILS
Contains
!
subroutine Calling
10  call Called(*10,'F')
return
end subroutine Calling
!
subroutine Called( *, FileorDir, Quiet)
! * Return 1 on error
!
character*1, intent(in), optional :: FileOrDir
logical*1,   intent(in), optional :: Quiet
return
end subroutine Called
!
end module UTILS


Alan
0 Kudos
Steven_L_Intel1
Employee
994 Views
Alan,

You are using an explicit interface - it's in the module. Your case is a bug - the alternate return (yuck!) is throwing off the compiler's argument checker. BTW, it says argument #4 because CHARACTER arguments count as two. Confusing, I know. We should really clean this up someday...

Steve
0 Kudos
llynisa
Beginner
994 Views
Steve,

Thanks for that - but I have not found any reference in the User's Guide or the Language Reference Manual to the fact that putting subroutines with optional arguments into modules produces explicit interfaces. I suspect that I am not alone here.

I am also trying to find similar guidance for dynamically declaring arrays in subroutines - I know that the following works for arrays B & C, but again I can find nor reference (perhaps I am not very good at ferreting these things out).
Subroutine ABCD(A,N)
Integer*4, intent(in) :: N
Real*8,    intent(in) :: A(N)
Real*8 B(N), C(N)
return
end

Alan
0 Kudos
Steven_L_Intel1
Employee
994 Views
Alan,

See my article on the topic of explicit interfaces in the Visual Fortran newsletter. The Language Reference Manual isn't intended to teach the Fortran language, and the nuances of explicit interfaces are more a matter for a tutorial.

For your array question, see the LRM index under "Automatic arrays".

Steve
0 Kudos
llynisa
Beginner
994 Views
Steve,

Thanks for the references ? but I still maintain that something as important as modules providing explicit interfaces should be in the LRM. On dynamic sizing of arrays, I will add ?Automatic? to my list of words that mean something different in Fortran: the prime example is ?Parameter?.

You don?t seem to like alternate returns, which I use when it is even less elegant not to use them, but the Fortran File I/O intrinsic statements are effectively full of them in the form of eg ERR=label, END=label, etc. But I have not heard of their being deprecated!

Alan
0 Kudos
Steven_L_Intel1
Employee
994 Views
I'll suggest to our writers that they enhance the section of the manual discussing explicit interfaces.

Steve
0 Kudos
Reply