I cannot access the values inside the Fortran labelled common blocks and I haven't found any example about this problem.
I'm able to call the Fortran routine that I've put inside a module but I cannot access to the Common Block Variables and notwithstanding several attempts I've always got zeros for the variables in common blocks.
I've created two separate projects one for C++ Console and one for Fortran dynamic link library inside a solution, in which the C++ project depends on the Fortran project.
Thank You very much for your answers in advance.
Carlo Timossi
What I have tried:
C++ code:
#include <iostream>
typedef struct
{
short int nstream;
short int nunit;
short int ncomp;
} generaltype;
typedef struct
{
float tau;
} PItype;
extern "C" {
generaltype general;
PItype pi;
}
extern "C" {
void ADD1(void);
}
int main()
{
ADD1();
std::cout << general.ncomp;
std::cout << general.nunit;
std::cout << general.ncomp;
std::cout << pi.tau;
}
Fortran code:
module testfor
use, intrinsic :: iso_c_binding
implicit none
contains
subroutine ADD1() bind(C,name="ADD1")
!DEC$ ATTRIBUTES DLLEXPORT:: ADD1
implicit none
include "Comm.for"
nstream=5
nunit=1
ncomp=3
tau = 3.14159
return
end subroutine
end module testfor
Comm.for code:
REAL tau
!DEC$ ATTRIBUTES alias:'pi' :: pi
COMMON /pi/ tau
INTEGER(2) nstream, nunit, ncomp
!DEC$ ATTRIBUTES alias:'general' :: general
COMMON /general/ nstream, nunit, ncomp