I want to call a Fortran subroutine, which I don't want to recode and which takes a assumed-shape array as input, from a C++ file. However if I pass a pointer (to handle the call by reference situation) on my allocated C++ array to the Fortran subroutine the application segfaults.
C++-file
#include <cstdlib>
extern "C" {
void __fma_MOD_printvector2(int**);
}
int main(int argc, char const *argv[])
{
int *vectorB = (int *)malloc(5*sizeof(vectorB));
for(int i = 0; i < 5; i++)
{
vectorB[i] = i+10;
}
__fma_MOD_printvector2(&vectorB);
return 0
}
Fortran-file:
MODULE fma
IMPLICIT NONE
CONTAINS
SUBROUTINE printVector2(a)
INTEGER, DIMENSION(:), INTENT(IN) :: a
INTEGER :: i
DO i=1,size(a)
WRITE(*,*) a(i)
END DO
END SUBROUTINE printVector2
END MODULE fma
Output:
10
[1] 5080 segmentation fault (core dumped) ./main.x
Any ideas where I'm wrong?