Question about C++ call Fortran with complicated data structure

Question about C++ call Fortran with complicated data structure

Dear all,

I am trying to call fortran from C++ project. The C++project is compiled by VS2003 and fortran code is compiled into DLL by Intel Fortran Compiler XE 14. There are very complicated data structure to be passed from C++ to Fortran (struct, pointer, link, char, etc.). Several years ago when the fortran DLL is compiled by Intel Fortran 9.x, everything is OK. However, when the Intel Compiler upgraded to XE 14, there are some problems: the value passed from C++ struct is not correct when in fortran code so the code crashed in the fortran code. At that time I was told to define some descriptor in C++ struct to align data between C++ and fortran code. For example, in fortran code, the structure is defined as follows:

type fortrantype





end type

In C++ the correspondent struct should be defined as follows:

typedef struct fortrantype
    int *i;


  struct mylist *list;
#ifdef WIN64
  char                list_fortran_descriptor[64];
  char                list_fortran_descriptor[32];
#endif //#ifdef WIN64



My question is: how to let the fortran code also work after the compiler upgraded to XE 14 (currently C++ compiler can't be upgraded because the C++ project is very huge and there are thousands of errors when upgrade to latest C++ compiler)? I noticed that the help document tell me how to communicate between fortran and C++:

However, I have to call functions

C_F_POINTER and c_loc

every time I use C pointer from Fortran or use Fortran pointer from C, there are tens of pointers and links in the struct and they are used very frequently in Fortran code, therefore, it will take a very long time to modify the code and debug it. Is there any simpler method to port the fortran code to latest fortran compiler?


Zhanghong Tang

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.