Я пытаюсь представить некоторые подпрограммы на Фортране как c_funptr
(void *
), чтобы создать словарь с помощью библиотеки fdict . Следуя документам GCC здесь Я попытался позвонить c_funloc
. Однако gfortran, похоже, возвращает массив c_funptr
вместо скалярного значения.
Это ошибка в компиляторе или я упускаю что-то важное?
Вывод из gfortran -v
:
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=auto
Thread model: posix
gcc version 8.3.0 (GCC)
Я также пытался использовать ifort (версия 19.0.2.187), и это дает желаемое поведение (см. Ниже).
MWE:
! = minimum.f90 =
module test
use iso_c_binding
implicit none
interface test_funptr
module procedure test_funptr0
module procedure test_funptr1
end interface test_funptr
contains
subroutine test_funptr0(fp)
type(c_funptr) :: fp
write(*,*) "fp0!"
end subroutine test_funptr0
subroutine test_funptr1(fp)
type(c_funptr), dimension(:) :: fp
write(*,*) "fp1!", shape(fp)
end subroutine test_funptr1
function bar(x) result(y) bind(c)
real(c_double) :: x
real(c_double) :: y
y = -x**2 + x + 1
end function bar
end module test
program main
use iso_c_binding
use test
implicit none
call test_funptr(c_funloc(bar))
end program main
скомпилировано с gfortran minimum.f90 -o min
Ожидаемый результат везде:
fp0
Реальное поведение: fp1
с нулевой формой для gfortran, fp0
для компилятора Intel.
Может быть, мне просто не хватает подходящего варианта для gfortran?