Accessing allocatable arrays from C++

Accessing allocatable arrays from C++

I know there are lots of topics about this issue, but I still can't figure out how to do it. Sorry...

I am working on a mixed fortran/C++ code (VS2010/IVF 2013.1.119). The fortan part is quite old (most is fortran IV). Up to now, all variables are in COMMON blocks, and accessed by C++ using extern "C" struct.

However, I am now implementing some new features using modules and allocatable variables, that must also be accessed by C++. I've searched and read about it, but could not make it work. BTW: my knowledge of C++ is very, very basic.

The original code for the module is:

    module AreaData
    implicit none
    integer(4) :: CaseNumArea
    real(8), dimension(:), allocatable ::  areaINTER
    integer(4), dimension(:), allocatable :: area2ext
    character(len=36), dimension(:), allocatable :: areaNOME   
    integer(4) :: ext2area(998)
    logical(1), dimension(:), allocatable :: areaLFRSelect  
    end module AreaData

As long as I could figure out, I should include use iso_c_bindind, change interger(4) to integer(C_INT), real(8) to real(C_DOUBLE), logical(1) to logical(C_BOOL). The basic questions: (i) what about the character variable? (ii) how would the C++ code look like? (iii) is it necessary to use BIND(C)?

Thanks for the help.

Andrea

PS: How do I insert a code block into the post?

2 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

There is nothing that directly corresponds to a Fortran array of character strings that I can think of. You could make it an array of structs with the struct containing a char[36]. The allocatable attribute isn't something you can play with on the C++ side at this time, but there's no problem passing allocatable arrays as ordinary data.

Steve - Intel Developer Support

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen