3

在带有 Intel Fortran 10.1 的 Windows 64 上使用 Visual Studio 9

我有一个调用 Fortran 的 C 函数,传递一个文字字符串“xxxxxx”(非空终止)和隐藏的传递长度 arg 6。

Fortran 正确,因为调试器识别出它是一个 character(6) var 并且具有正确的字符串,但是当我尝试为其分配另一个 Fortran character*6 var 时,我得到了最奇怪的错误。

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

-- C 调用 --

SETPR("abcdef",6);

-- Fortran 子程序 --

subroutine setpr(vstring)

character*(*) vstring

character*6 prd

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

return

end
4

1 回答 1

1

我使用英特尔 C 编译器和英特尔 Fortran 编译器进行了尝试。这在 C 中给出了,

#include <stdio.h>

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

    test_f_("abcdef",6);
}

并且,在 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

编译并运行时,它会产生

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

您在 C 例程中对 Fortran 例程类型的声明是什么?您确定 C 和 Fortran 代码之间的字符和整数变量的大小相同吗?

于 2009-04-27T16:53:33.923 回答