[Fortran] 纯文本查看 复制代码
PROGRAM test
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_BOOL
LOGICAL*1 :: byte_1_logical ! kind of 1-byte
LOGICAL(1) :: kind_1_logical ! kind number is 1
LOGICAL :: default_logical ! default kind
WRITE(*,*) C_BOOL !---> 1-byte
! report the kind nunmbes
WRITE(*,*) KIND(byte_1_logical)
WRITE(*,*) KIND(kind_1_logical)
WRITE(*,*) KIND(default_logical)
! Many compilers support 1-, 2- 4- 8-byte LOGICALs
! kind numbers may be (1,2,3,4) or (1,2,4,8), compiler-time-switch dependent
END PROGRAM test
[Fortran] 纯文本查看 复制代码
FUNCTION f(a, b)
IMPLICIT NONE
LOGICAL, INTENT(IN ) :: a
LOGICAL, INTENT( OUT) :: b
LOGICAL :: f
INTERFACE ! [C] bool c(bool a, bool *b)
FUNCTION c(a, b) BIND(C,NAME='c')
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_BOOL
IMPLICIT NONE
LOGICAL(C_BOOL), VALUE :: a
LOGICAL(C_BOOL) :: b
END FUNCTION c
END INTERFACE
LOGICAL(C_BOOL) :: bb
!---------------
f = c(LOGICAL(a,KIND=C_BOOL), bb)
b = bb
! there should be no problem: assign "1-byte" to "4-byte"
END FUNCTION f