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

String arguments and string length

OP1
New Contributor III
632 Views
Hi,

I would like to check that my understanding of how Fortran handles string arguments is correct.

When using the default calling convention, IVF passes the length of the string arguments at the end of all arguments. For instance the subroutine

SUBROUTINE TEST(A,B,C,D)
IMPLICIT NONE
CHARACTER(LEN=10),INTENT(IN) :: A
REAL(8),INTENT(IN) :: B
CHARACTER(LEN=50),INTENT(IN) :: C(10)
LOGICAL,INTENT(OUT) :: D
...
END SUBROUTINE TEST

would actually have an *interface* that looks like: TEST(A,B,C,D,len_a,len_c) where len_a = 10 and len_c = 50 (ie, that is how it should be called from a JAVA code for instance).

Is this correct? Does the presence of the character array C complicate things?

Thanks,

Olivier
0 Kudos
3 Replies
mecej4
Honored Contributor III
632 Views
You are correct, but in a restricted sense. Knowledge about the protocol for passing string length arguments is needed only if only if you do not use the C-interoperability module. In that case, the compiler vendor is free to implement the passing of hidden length arguments. Indeed, Intel Fortran and Compaq Visual Fortran used a different order for passing the arguments.

A second issue connected to mixed-language programming involves name decoration. This is also something that you will need to work with, and compilers usually provide options for controlling how the decoration is done.
0 Kudos
OP1
New Contributor III
632 Views
Thanks,

Yes - I just want to double check for the character array that I just need to pass one extra integer representingthe string length of its elements (as opposed toan extra array containing thestring lengths for all of the character array elements).

Olivier
0 Kudos
Steven_L_Intel1
Employee
632 Views
Make sure that the length you pass is an address-sized integer. INTEGER(4) on IA-32, INTEGER(8) on x64.
0 Kudos
Reply