I am learning about fortran C++ interoperability. In this case I was trying to write a 'wrapper' function (f_mult_wrapper) to interface between my 'pure' fortran function (f_mult) and C++. The function is defined in my C code as
double f_mult_by_wrapper(double i, double j);
and called like
double u=f_mult_by_wrapper(w,r);
I know I must specify that the input arguments in f_mult_wrapper are being passed by value from C, and that fortran usually passes by reference. But the compiler gives me an error when I try to specify that the result is being passed by value: A dummy argument name is required in this context. The code works together as written, but I don't exactly understand why.
module type_example
use :: iso_c_binding
function f_mult(i,j) result(k)
! use fortran intrinsic types
real:: i,j,k
k = i*j;
end function
function f_mult_wrapper(aw,bw) result(cw) bind(c,name="f_mult_by_wrapper");
real(c_double), VALUE :: aw ! use c binding types. passed by value
real(c_double), VALUE :: bw
real(c_double) :: cw
real :: a,b,c
a = aw
b = bw
c = cw
c = f_mult(a,b)
cw = c
end function
end module