Last active
July 16, 2018 22:25
-
-
Save belmarca/f3bef48cc14055c8445a476709bbdf9a to your computer and use it in GitHub Desktop.
Calling Fortran from Gambit-C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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