host_is_little_endian Function

public pure function host_is_little_endian() result(is_little)

Report whether the running machine stores the least significant byte of an integer first.

The probe is a transfer between two integer kinds, int8 to int32. A transfer between a real and an integer kind is deliberately avoided here: it is the construct whose behaviour is least dependable across nvfortran and LFortran, and there is no reason to risk it when an integer only probe answers the same question. Arithmetic alone, iand or ishft, cannot answer it at all, since those operate on values rather than on the storage order of the bytes.

Arguments

None

Return Value logical


Source Code

   pure function host_is_little_endian() result(is_little)
      !! Report whether the running machine stores the least significant byte
      !! of an integer first.
      !!
      !! The probe is a `transfer` between two *integer* kinds, `int8` to
      !! `int32`. A `transfer` between a real and an integer kind is
      !! deliberately avoided here: it is the construct whose behaviour is
      !! least dependable across nvfortran and LFortran, and there is no reason
      !! to risk it when an integer only probe answers the same question.
      !! Arithmetic alone, `iand` or `ishft`, cannot answer it at all, since
      !! those operate on values rather than on the storage order of the bytes.
      logical :: is_little

      is_little = (transfer([1_int8, 0_int8, 0_int8, 0_int8], 0_int32) == 1_int32)
   end function host_is_little_endian