1! { dg-do run }
2! Support F2008's c_sizeof()
3!
4use iso_c_binding, only: c_int, c_char, c_ptr, c_intptr_t, c_null_ptr, c_sizeof
5
6integer(kind=c_int) :: i, j(10)
7character(kind=c_char,len=4),parameter :: str(1 ) = "abcd"
8character(kind=c_char,len=1),parameter :: str2(4) = ["a","b","c","d"]
9type(c_ptr) :: cptr
10integer(c_intptr_t) :: iptr
11
12! Using F2008's C_SIZEOF
13i = c_sizeof(i)
14if (i /= 4) call abort()
15
16i = c_sizeof(j)
17if (i /= 40) call abort()
18
19i = c_sizeof(str2)
20if (i /= 4) call abort()
21
22i = c_sizeof(str2(1))
23if (i /= 1) call abort()
24
25i = c_sizeof(str2(1:3))
26if (i /= 3) call abort()
27
28write(*,*) c_sizeof(cptr), c_sizeof(iptr), c_sizeof(C_NULL_PTR)
29
30! Using GNU's SIZEOF
31i = sizeof(i)
32if (i /= 4) call abort()
33
34i = sizeof(j)
35if (i /= 40) call abort()
36
37i = sizeof(str)
38if (i /= 4) call abort()
39
40i = sizeof(str(1))
41if (i /= 4) call abort()
42
43i = sizeof(str(1)(1:3))
44if (i /= 3) call abort()
45
46end
47
48