iso_fortran_env exposes named kind constants. real32 is 32-bit (kind 4) and real64 is 64-bit (kind 8) on common platforms.

Program

Play the program to print the kind numbers behind real32 and real64.

kinds.f90
Replay: real traced execution (multi-file project)
program kinds_demo
    use iso_fortran_env, only: real32, real64
    implicit none
    integer :: k32, k64
    k32 = real32
    k64 = real64
    print '(I0, A, I0)', k32, " ", k64
end program kinds_demo
  1. k32 ← 4

    4integer :: k32, k645k32 = real326k64 = real64
    values this step4k32
  2. k64 ← 8

    5k32 = real326k64 = real647print '(I0, A, I0)', k32, " ", k64
    values this step8k64
  3. print '(I0, A, I0)', k32, " ", k64

    6    k64 = real647    print '(I0, A, I0)', k32, " ", k648end program kinds_demo
    output4 8
    values this step4k328k64

Follow the Kinds

  1. The program imports real32 and real64.
  2. k32 = real32 stores 4.
  3. k64 = real64 stores 8.
  4. The print statement writes both numbers with one space between them.
  5. The output is 4 8. | name | stored value | | --- | --- | | k32 | 4 | | k64 | 8 | | stdout | 4 8 |
iso_fortran_env Standard module exposing portable kind constants.
real32 / real64 Named constants for 32-bit and 64-bit real kinds.
only: `only:` imports just the names you need.

Exercise: kinds.f90

Reproduce the output 4 8, then trace how real32 fills k32 with 4 and real64 fills k64 with 8.