passing char arrays from c++ to fortran

前端 未结 3 466
鱼传尺愫
鱼传尺愫 2020-12-17 02:23

I am having trouble passing char arrays from c++ to fortran (f90).

Here is my c++ file, \'cmain.cxx\':

#include 

using namespace std         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 02:49

    I recommend using the ISO C Binding on the Fortran side as suggested by "High Performance Mark". You are already using "extern C". The ISO C Binding of Fortran 2003 (currently implemented in most Fortran 95 / partial Fortan 2003 compilers) makes this a compiler and platform independent approach. Charles Bailey described the differences between strings in the two languages. This Stackoverflow question has a code example: Calling a FORTRAN subroutine from C

    If you don't want to modify existing Fortran code you could write a "glue" routine in between your C++ code and the existing Fortran code. Writing the glue routine in Fortran using the ISO C Binding would be more reliable and stable since this would be based on the features of a language standard.

提交回复
热议问题