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

External subroutine acting on optional character arguments

OP1
New Contributor III
598 Views
I am trying to build a static library which contains a subroutine which does this:

SUBROUTINE S(A,B,C)
IMPLICIT NONE
INTEGER,INTENT(IN) :: A
CHARACTER(10),INTENT(IN),OPTIONAL :: B
CHARACTER(20),INTENT(IN),OPTIONAL :: C
CHARACTER(*) UPCASE
...
IF (PRESENT(B)) THEN
WRITE(*,*) UPCASE(B)
ENDIF
IF (PRESENT(C)) THEN
WRITE(*,*) UPCASE(C)
ENDIF
...
END SUBROUTINE S

When in my code Band Care not passed to A a build error occurs. Ifthey arepresent then the code builds (and run) properly. The build error comes from the external subroutine UPCASE (which just does an upper case conversion of the strings B and C) which can not be linked if B and C are not present.

How can I get around the fact that S (a library subroutine) may or may not be called by my customers' programs with or without B and C- and therefore may trigger build errors?

Thanks!

Olivier
0 Kudos
3 Replies
Steven_L_Intel1
Employee
598 Views
You left out some important points, such as which compiler you used and whether or not an explicit interface for subroutine S was visible to the caller. I'm going to guess 1) CVF and 2) No. If you correct #2, the build (and execution) issues should go away.

An explicit interface is required to be visible when calling a routine with an OPTIONAL argument. Ideally, subroutine S would be in a MODULE that is USEd by the caller, or is a CONTAINed procedure.


0 Kudos
OP1
New Contributor III
598 Views
You left out some important points, such as which compiler you used and whether or not an explicit interface for subroutine S was visible to the caller. I'm going to guess 1) CVF and 2) No. If you correct #2, the build (and execution) issues should go away.

An explicit interface is required to be visible when calling a routine with an OPTIONAL argument. Ideally, subroutine S would be in a MODULE that is USEd by the caller, or is a CONTAINed procedure.



I am using IVF 10 - and there was an explicit interface to S. But it turns out I had to declare an explicit interface for UPCASE in S as well. It works now.

Thanks for your help!

Olivier
0 Kudos
Steven_L_Intel1
Employee
598 Views
Curious - what were the build errors before? Are you using /iface:cvf?
0 Kudos
Reply