Skip to content

Commit 9071b1b

Browse files
committed
add example associated/c_associated
1 parent f5154b2 commit 9071b1b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/poly_type/lib.f90

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module poly_type
22

3-
use, intrinsic :: iso_c_binding, only : C_PTR, c_loc, c_int, c_f_pointer
3+
use, intrinsic :: iso_c_binding, only : C_PTR, c_loc, c_int, c_f_pointer, c_associated
44

55
implicit none (type, external)
66

@@ -49,8 +49,11 @@ subroutine init_type(xtype, xC) bind(C)
4949
select case (xtype)
5050
case (3)
5151
allocate(three)
52+
if(.not.associated(three)) error stop "three not associated with Fortran"
5253
xC = c_loc(three)
54+
if (.not. c_associated(xC)) error stop "three not associated with C"
5355
x=>three
56+
if(.not.associated(x, three)) error stop "x Fortran pointer not associated"
5457
case (4)
5558
allocate(four)
5659
xC = c_loc(four)

0 commit comments

Comments
 (0)