8.241 SELECTED_LOGICAL_KIND — Choose logical kind

Description:

SELECTED_LOGICAL_KIND(BITS) return the kind value of the smallest logical type whose storage size in bits is at least BITS. If there is no such logical kind, SELECTED_LOGICAL_KIND returns -1.

Standard:

Fortran 2023 and later

Class:

Transformational function

Syntax:

RESULT = SELECTED_LOGICAL_KIND(BITS)

Arguments:
BITSShall be a scalar and of type INTEGER.
Example:
program logical_kinds
  integer, parameter :: k1 = selected_logical_kind(1)
  integer, parameter :: k40 = selected_logical_kind(40)
  logical(kind=k1) :: l1    ! At least one bit
  logical(kind=k40) :: l40  ! At least 40 bits

  ! What is their actual size?
  print *, storage_size(l1), storage_size(l40)
end program logical_kinds