Reputation: 201
Using Visual Studio 9 on Windows 64 with Intel Fortran 10.1
I have a C function calling Fortran, passing a literal string "xxxxxx" (not null terminated) and the hidden passed length arg 6.
Fortran gets it right since the debugger recognizes it's a character(6) var and has the correct string, but when I try to assign another Fortran character*6 var to it I get the oddest error.
forrtl: severe (408): fort: (4): Variable Vstring has substring ending point 6 which is greater than the variable length 6
-- C call --
SETPR("abcdef",6);
-- Fortran subroutine --
subroutine setpr(vstring)
character*(*) vstring
character*6 prd
prd(1:6) = vstring(1:6)
return
end
Upvotes: 3
Views: 937
Reputation: 10677
I tried this with the Intel C compiler and the Intel Fortran compiler. This gave, in C,
#include <stdio.h>
int main(void)
{
extern void test_f_(char*, int);
test_f_("abcdef",6);
}
and, in Fortran,
subroutine test_f(s)
implicit none
character*(*), intent(in) :: s
character*6 :: c
write (*,*) 'S is ', s
write (*,*) 'Length of S is', len(s)
c = s
write (*,*) 'Implicit-copied C is ', c
c(1:6) = s(1:6)
write (*,*) 'Range-copied C is ', c
end subroutine test_f
When compiled and run, it produces
S is abcdef
Length of S is 6
Implicit-copied C is abcdef
Range-copied C is abcdef
What is your declaration in the C routine for the type of the Fortran routine? Are you sure that the sizes of character and integer variables are the same between the C and Fortran code?
Upvotes: 1