2 ! { dg-additional-sources c_f_pointer_shape_tests_2_driver.c }
3 ! Verify that the optional SHAPE parameter to c_f_pointer can be of any
4 ! valid integer kind. We don't test all kinds here since it would be
5 ! difficult to know what kinds are valid for the architecture we're running on.
6 ! However, testing ones that should be different should be sufficient.
7 module c_f_pointer_shape_tests_4
8 use, intrinsic :: iso_c_binding
11 subroutine test_long_long_1d(cPtr, num_elems) bind(c)
12 use, intrinsic :: iso_c_binding
13 type(c_ptr), value :: cPtr
14 integer(c_int), value :: num_elems
15 integer, dimension(:), pointer :: myArrayPtr
16 integer(c_long_long), dimension(1) :: shape
20 call c_f_pointer(cPtr, myArrayPtr, shape)
22 if(myArrayPtr(i) /= (i-1)) call abort ()
24 end subroutine test_long_long_1d
26 subroutine test_long_long_2d(cPtr, num_rows, num_cols) bind(c)
27 use, intrinsic :: iso_c_binding
28 type(c_ptr), value :: cPtr
29 integer(c_int), value :: num_rows
30 integer(c_int), value :: num_cols
31 integer, dimension(:,:), pointer :: myArrayPtr
32 integer(c_long_long), dimension(3) :: shape
38 call c_f_pointer(cPtr, myArrayPtr, shape(1:3:2))
41 if(myArrayPtr(i,j) /= ((j-1)*num_rows)+(i-1)) call abort ()
44 end subroutine test_long_long_2d
46 subroutine test_long_1d(cPtr, num_elems) bind(c)
47 use, intrinsic :: iso_c_binding
48 type(c_ptr), value :: cPtr
49 integer(c_int), value :: num_elems
50 integer, dimension(:), pointer :: myArrayPtr
51 integer(c_long), dimension(1) :: shape
55 call c_f_pointer(cPtr, myArrayPtr, shape)
57 if(myArrayPtr(i) /= (i-1)) call abort ()
59 end subroutine test_long_1d
61 subroutine test_int_1d(cPtr, num_elems) bind(c)
62 use, intrinsic :: iso_c_binding
63 type(c_ptr), value :: cPtr
64 integer(c_int), value :: num_elems
65 integer, dimension(:), pointer :: myArrayPtr
66 integer(c_int), dimension(1) :: shape
70 call c_f_pointer(cPtr, myArrayPtr, shape)
72 if(myArrayPtr(i) /= (i-1)) call abort ()
74 end subroutine test_int_1d
76 subroutine test_short_1d(cPtr, num_elems) bind(c)
77 use, intrinsic :: iso_c_binding
78 type(c_ptr), value :: cPtr
79 integer(c_int), value :: num_elems
80 integer, dimension(:), pointer :: myArrayPtr
81 integer(c_short), dimension(1) :: shape
85 call c_f_pointer(cPtr, myArrayPtr, shape)
87 if(myArrayPtr(i) /= (i-1)) call abort ()
89 end subroutine test_short_1d
91 subroutine test_mixed(cPtr, num_elems) bind(c)
92 use, intrinsic :: iso_c_binding
93 type(c_ptr), value :: cPtr
94 integer(c_int), value :: num_elems
95 integer, dimension(:), pointer :: myArrayPtr
96 integer(c_int), dimension(1) :: shape1
97 integer(c_long_long), dimension(1) :: shape2
100 shape1(1) = num_elems
101 call c_f_pointer(cPtr, myArrayPtr, shape1)
103 if(myArrayPtr(i) /= (i-1)) call abort ()
107 shape2(1) = num_elems
108 call c_f_pointer(cPtr, myArrayPtr, shape2)
110 if(myArrayPtr(i) /= (i-1)) call abort ()
112 end subroutine test_mixed
113 end module c_f_pointer_shape_tests_4