File: bindc_03.f90

package info (click to toggle)
lfortran 0.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 46,332 kB
  • sloc: cpp: 137,068; f90: 51,260; python: 6,444; ansic: 4,277; yacc: 2,285; fortran: 806; sh: 524; makefile: 30; javascript: 15
file content (38 lines) | stat: -rw-r--r-- 868 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
subroutine fn() bind(c)
print *, "Hello from fn in fortran"
end subroutine

subroutine test_val( val ) bind(c)
use iso_c_binding
integer(c_int), value :: val
print *, "val = ", val
if ( val /= 42 ) error stop
end subroutine

program bindc_03
use iso_c_binding
implicit none
interface
subroutine fn() bind(c)
end subroutine

subroutine test_val( val ) bind(c)
import :: c_int
integer(c_int), value :: val
end subroutine

subroutine execute_function( fn ) bind(c, name = "execute_function")
import :: c_funptr
type(c_funptr), value :: fn
end subroutine

subroutine execute_function_with_arg( fn, val ) bind(c, name = "execute_function_with_arg")
import :: c_funptr, c_int
integer(c_int), value :: val
type(c_funptr), value :: fn
end subroutine
end interface

call execute_function( c_funloc( fn ) )
call execute_function_with_arg( c_funloc( test_val ), 42 )
end program