File: bindc4.f90

package info (click to toggle)
lfortran 0.59.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 56,736 kB
  • sloc: cpp: 168,052; f90: 74,272; python: 17,537; ansic: 7,705; yacc: 2,345; sh: 1,334; fortran: 895; makefile: 37; javascript: 15
file content (50 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
44
45
46
47
48
49
50
program bindc4
use iso_c_binding, only: c_associated, c_loc, c_ptr, c_f_pointer, c_null_ptr
type(c_ptr) :: queries
type(c_ptr) :: queries2 = c_null_ptr
integer :: i, j
integer(2), target :: xv(3, 4), yv(3,4)
integer :: newshape(2)
integer(2), pointer :: x(:, :), y(:,:)

newshape(1) = 2
newshape(2) = 3

x => xv
y => yv

do i = lbound(x, 1), ubound(x, 1)
    do j = lbound(x, 2), ubound(x, 2)
        print *, i, j, c_loc(x(i, j))
    end do
end do

call c_f_pointer(queries, x, newshape)

print *, c_loc(x), queries

do i = lbound(x, 1), ubound(x, 1)
    do j = lbound(x, 2), ubound(x, 2)
        print *, i, j, c_loc(x(i, j))
    end do
end do

call c_f_pointer(queries, x, [3, 4])

print *, c_loc(x), queries

do i = lbound(x, 1), ubound(x, 1)
    do j = lbound(x, 2), ubound(x, 2)
        print *, i, j, c_loc(x(i, j))
    end do
end do

if (.not. c_associated(queries, c_loc(x(1, 1)))) error stop
if (.not. c_associated(queries, c_loc(x))) error stop
if (c_associated(queries, c_loc(y))) error stop
if (c_associated(queries2)) error stop
! TODO: Fix the following test
!if (.not. c_associated(queries)) error stop
queries = c_null_ptr

end program