Hi! I create a fortran dll that it can pass an array to sum its elements and call a c function below:
module callctest use, intrinsic :: iso_c_binding implicit none private public callcfun contains subroutine callcfun(a,b) bind(C,name = "callcfun") !DEC$ ATTRIBUTES DLLEXPORT :: callcfun implicit none real(c_double), dimension(*):: a !receive an array from c type(c_funptr), value :: b ! receive a c function real, parameter::pi=3.14159 integer :: i real :: sum = 0.0 do i = 1,3 ! sum the array elements sum = sum+a(i) end do write(*,*) 'total',sum return end subroutine callcfun end module callctest
And c code that it call fortran with passing c function that it print words and an input integer:
#include "stdafx.h" #include <iostream> using namespace std; extern "C" { void callcfun( double[], void(f)(int)); // } void sayhello(int a){ cout << "Hi! fortran "<<a<< endl; } int main(){ double a[] = { 10.0, 50, 3.0 }; callcfun(a, sayhello(50)); system("pause"); return 0; }
But the problem in function sayhello(50). Error list shows:
Error 1 error C2664: 'void callcfun(double [],void (__cdecl *)(int))' : cannot convert argument 2 from 'void' to 'void (__cdecl *)(int)'
IntelliSense: argument of type "void" is incompatible with parameter of type "void (*)(int b)"
How to solve it? Thanks!
Thread Topic:
Question