mixing gfortran and C++

Gengbin Zheng zhenggb@gmail.com
Thu Oct 25 01:57:00 GMT 2007


Hi,

 I have a question about calling a C++ function from gfortran.

 The fortran interface of the C++ function is like this:

      SUBROUTINE COM_SET_MEMBER_FUNCTION( WF_NAME, FUNC, &
              WA_NAME, INTENTS, TYPES)
           CHARACTER(*), INTENT(IN) :: WF_NAME, WA_NAME, INTENTS
           INTEGER, INTENT(IN) :: TYPES(1)
           EXTERNAL FUNC
         End SUBROUTINE COM_SET_MEMBER_FUNCTION

so we have 3 character strings wf_name, wa_name and intents.
In C++ it is defined as:

void com_set_member_function( const char *wf_str, Func_ptr func, const
char *wa_str, const char *intents,   const COM_Type *types, long int
wf_len, long int a_len, long int i_len);

  As a common practice, you can see we added three additional long
ints at the end of the above call to receive the lengths of the three
strings.
Now when we run the program in gdb, I see that those length fields
(wf_len, a_len, i_len) are messed up, some are correct and others are
not with some ridiculous large number.
My question is that am I doing it the correct way?
thanks,



More information about the Fortran mailing list