Use another language to call a function: Difference between revisions

(Added alternative Go solution (after summary message mess up))
Line 229:
 
To use this function from C you have to export this as a DLL and bind your C program to this function.
 
== Fortran ==
Simple task because interoperability with C is in Fortran language since F2003 standard.
<lang Fortran>
!-----------------------------------------------------------------------
!Function
!-----------------------------------------------------------------------
function fortran_query(data, length) result(answer) bind(c, name='Query')
use, intrinsic :: iso_c_binding, only: c_char, c_int, c_size_t, c_null_char
implicit none
character(len=1,kind=c_char), dimension(length), intent(inout) :: data
integer(c_size_t) :: length
integer(c_int) :: answer
answer = 0
if(length<10) return
data = transfer("Here I am"//c_null_char, data)
length = 10_c_size_t
answer = 1
end function fortran_query
</lang>
compile it: gfortran main.c query.f90 -o main.x
 
=={{header|Go}}==
Anonymous user