11module logbool
22
3- use , intrinsic :: iso_c_binding, only : C_BOOL, C_INT
3+ use , intrinsic :: iso_c_binding
4+ use , intrinsic :: iso_fortran_env
45
56implicit none
67
7- contains
8+ type, bind(C) :: bool_args
9+ logical (C_BOOL) :: value
10+ integer (C_INT) :: dummy
11+ end type
812
9- logical (c_bool) function logical_not(L, dummy) bind(C)
13+ contains
1014
11- logical (c_bool), intent ( in ), value :: L
12- integer (c_int ), intent (in ) :: dummy
15+ logical (C_BOOL) function logical_not(args) bind(C)
16+ type (bool_args ), intent (in ), value :: args
1317
14- logical_not = .not. L
18+ logical_not = .not. args % value
1519
16- print ' (/, a, l1, a, l1)' , " logical_not(" , L , " ): " , logical_not
20+ print ' (/, a, l1, a, l1)' , " logical_not(" , args % value , " ): " , logical_not
1721
1822print ' (a16,2x,a,2x,a8,2x,a8)' , " storage_size()" , " bits" , " hex(in)" , " hex(out)"
19- print ' (a16,2x,i3,2x,z8,2x,z8)' , " C_BOOL: " , storage_size(L ), L , logical_not
23+ print ' (a16,2x,i3,2x,z8,2x,z8)' , " C_BOOL: " , storage_size(args % value ), args % value , logical_not
2024
21- if (dummy /= 42_c_int ) error stop " dummy argument should be 42"
22- ! print '(a)', "logical_not passed dummy argument correctly"
25+ if (args% dummy /= 42_C_INT ) then
26+ write (error_unit, ' (a,i0,a)' ) " bool_passthru passed dummy argument " , args% dummy, " but expected 42"
27+ error stop
28+ end if
2329
2430end function logical_not
2531
2632
27- logical (C_BOOL) function bool_passthru(L, dummy) bind(C)
28- logical (C_BOOL), intent (in ), value :: L
29- integer (C_INT), intent (in ) :: dummy
30- if (dummy /= 42_C_INT ) error stop " dummy argument should be 42"
31- bool_passthru = L
33+ logical (C_BOOL) function bool_passthru(args) bind(C)
34+ type (bool_args), intent (in ), value :: args
35+ if (args% dummy /= 42_C_INT ) then
36+ write (error_unit, ' (a,i0,a)' ) " bool_passthru passed dummy argument " , args% dummy, " but expected 42"
37+ error stop
38+ end if
39+ bool_passthru = args% value
3240end function bool_passthru
3341
3442
@@ -40,4 +48,4 @@ logical(C_BOOL) function bool_false() bind(C)
4048bool_false = .false. _C_BOOL
4149end function
4250
43- end module logbool
51+ end module
0 commit comments