Problem with C in Fortran

Using Visual Studio 9 on Windows 64 with Intel Fortran 10.1

I have a C function that calls Fortran, passing the string string "xxxxxx" (non-zero) and the hidden length of the arg argument.

Fortran gets this right because the debugger recognizes its symbol (6) var and has the correct string, but when I try to assign a different symbol to Fortran * 6 var, I get the strangest error.

forrtl: severe (408): fort: (4): Variable Vstring has substring ending point 6 which is greater than the variable length 6

- call C -

SETPR("abcdef",6);

- Fortran routine -

subroutine setpr(vstring)

character*(*) vstring

character*6 prd

prd(1:6) = vstring(1:6)

return

end
+3
source share
1 answer

I tried this with the Intel C compiler and the Intel Fortran compiler. It gave in C,

#include <stdio.h>

int main(void)
{
    extern void test_f_(char*, int);

    test_f_("abcdef",6);
}

and, at Fortran,

subroutine test_f(s)
    implicit none
    character*(*), intent(in) :: s

    character*6 :: c

    write (*,*)  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 compiling and running, it produces

S is abcdef
Length of S is           6
Implicit-copied C is abcdef
Range-copied C is abcdef

C Fortran? , C Fortran?

+1

Source: https://habr.com/ru/post/1706995/


All Articles