4

Fortran でこの単純なモジュールを取得しました。

test.f90 :

module test
   implicit none
contains

   subroutine foo(chid)
      implicit none
      character(len=*),intent(out):: chid          ! char. identifier
      chid = "foo"
   end subroutine foo
end module test

program bar
   use test
   character(len=20) text
   call foo(text)
   write(*,*) text
end program bar

それを(Windows上で)コンパイルしてgfortran test.f90 -o test.exe実行すると、予想どおり、次のようになります。

 foo

f2py を使用してコンパイルすることもできます。c:\Python27\python.exe c:\Python27\Scripts\f2py.py --fcompiler=gnu95 --compiler=mingw32 -c -m test \test.f90

この Python スクリプトを実行すると:

test.py :

from id_map import test

print "This should be 'foo':"
print test.foo()
print "was it?"

次の出力が得られます。

This should be 'foo':

was it?

ご覧のとおり、"foo" になるはずの文字列が空です。どうしてこれなの?

4

1 に答える 1