Skip to content

Instantly share code, notes, and snippets.

@belmarca
Last active July 16, 2018 22:25
Show Gist options
  • Save belmarca/f3bef48cc14055c8445a476709bbdf9a to your computer and use it in GitHub Desktop.
Save belmarca/f3bef48cc14055c8445a476709bbdf9a to your computer and use it in GitHub Desktop.
Calling Fortran from Gambit-C
gambit:
gfortran -c sum_to_n.f90 -o sum_to_n.o
gsc -ld-options sum_to_n.o sum_to_n.scm
clean:
rm sum_to_n.o*
integer function sum_to_n(n) result(sum) bind(C, name="sum_to_n")
use iso_c_binding
implicit none
integer, intent(in) :: n
integer :: i, s
s = 0
do i = 1, n
s = s + i
end do
sum = s
end function sum_to_n
(c-declare "int sum_to_n(int *n);")
(define sum-to-n (c-lambda (int) int "___return(sum_to_n(&___arg1));"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment