----------------------------------------------------------------------------------
@MSGID: 1@dont-email.me> 110e5d22
@REPLY: 1@dont-email.me> 8b6cbed6
@REPLYADDR Gary Scott <garylscott@sbcglobal.net>
@REPLYTO 2:5075/128 Gary Scott
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: 1@dont-email.me>
@RFC-References: 1@dont-email.me>
1@dont-email.me>
@TZUTC: -0500
@PID: Mozilla Thunderbird
@TID: FIDOGATE-5.12-ge4e8b94
I wonder if you add ISO_C_BINDING inside the function interface if it
helps resolve the reference.
On 9/30/2023 8:42 AM, db wrote:
> On 04.09.2023 16.43, db wrote:
>> I see that rather than try to convert a C++ function to
>> Fortran, it might be better to call it from a Fortran
>> program. So I found a description of how to do it, and
> I askked this both here and in the C++ ng. I got a lot of different
> advice, none of which worked. So I have now reduced it to a mini-
> example. Here is the Fortran program that calls a C++ function:
>
> program MINI_TEST
> use ISO_C_BINDING
> implicit none
> integer, parameter :: dbl=selected_real_kind(14)
> real(dbl) :: MINI, arg, arg2
> interface
> function MINI (tbar)
> real(c_double) :: MINI
> real(c_double) :: arg
> end function MINI
> end interface
> read *, arg
> arg2 = MINI (arg)
> print `(" MINI returned =", f10.4)`, arg2
> end program MINI_TEST
>
> The function is
>
> #include
> #include
> #include
> #include "math.h"
> using namespace std;
> const double mini(const double arg)
> {
> return arg * 2;
> }
>
>
> I know this works because I got a C++ calling program from
> a friend, that called it and the result is correct.
>
> I wrote a shell script to run this, using another suggestion
>
> gfortran -o minitest.out minitest.f90 mini.cpp -lstdc++ -lm
> ./minitest.out << eoi
> 1.0
> eoi
> rm minitest.out
>
> and ran that. The main problem is that it doesn`t recognise
> the C++ type c_double:
>
> minitest.f90:8:11:
>
> 8 | real(c_double) :: MINI
> | 1
> Error: Parameter `c_double` at (1) has not been declared or is a
> variable, which does not reduce to a constant expression
>
> (same for arg) plus a type mismatch arising from it.
>
> So: can you suggest how to make this work? If so, then
> I can implement that with the much longer actual function
> I am trying to call from Fortran.
>
>
--- Mozilla Thunderbird
* Origin: A noiseless patient Spider (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441