Question about C++ call Fortran with complicated data structure

Question about C++ call Fortran with complicated data structure

Portrait de tangzhanghong98@yahoo.com

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

    integer,pointer::i

    ...

    type(mylist),pointer::list(:)

    ...

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];
#else
  char                list_fortran_descriptor[32];
#endif //#ifdef WIN64

    ...

}mytype;

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++:

http://software.intel.com/sites/products/documentation/doclib/stdxe/2013...

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?

Thanks,

Zhanghong Tang

1 contribution / 0 nouveau(x)
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.