title: Integer precision in modern Fortran
body: <p>The value of <code>selected_int_kind(int16)</code> appears to 1 instead of 2. Is this a compiler bug?</p>
  
  <p>In the following output please note the discrepancy for <code>bint</code> which is intended to be 2 bytes, <code>INT16</code>. (The annotations &lt;=== were added for clarity.)</p>
  
  <pre><code>compiler version  = GCC version 5.1.0
  compiler options  = -fPIC -mmacosx-version-min=10.9.4 -mtune=core2 -Og -Wall -Wextra -Wconversion -Wpedantic -fcheck=bounds -fmax-errors=5
  execution command = ./a.out
  
  Number of bytes in type default = 4
  Number of bytes in type int_8 = 1
  Number of bytes in type int_16 = 2         &lt;===
  Number of bytes in type int_32 = 4
  Number of bytes in type int_64 = 8
  Number of bytes in type int_a = 1
  Number of bytes in type int_b = 1          &lt;===
  Number of bytes in type int_c = 2
  Number of bytes in type int_d = 4
  Value of aint = 1
  Value of bint = 1                          &lt;===
  Value of cint = 2
  Value of dint = 4
  Value of selected_int_kind ( INT16 ) = 1   &lt;===
  </code></pre>
  
  <p>The following code is supplied to allow readers to investigate this problem. The assignment in question is in line 13.</p>
  
  <pre><code>program bytes
      use iso_fortran_env
      implicit NONE
  
      integer           :: default
  
      integer ( int8  ) :: int_8
      integer ( int16 ) :: int_16
      integer ( int32 ) :: int_32
      integer ( int64 ) :: int_64
  
      integer, parameter :: aint = selected_int_kind ( INT8 )
      integer, parameter :: bint = selected_int_kind ( INT16 )
      integer, parameter :: cint = selected_int_kind ( INT32 )
      integer, parameter :: dint = selected_int_kind ( INT64 )
  
      integer ( aint ) :: int_a
      integer ( bint ) :: int_b
      integer ( cint ) :: int_c
      integer ( dint ) :: int_d
  
      character ( len = * ), parameter :: c_options = compiler_options( )
      character ( len = * ), parameter :: c_version = compiler_version( )
      character ( len = 255 )          :: cmd = " "
  
          call get_command ( cmd )
  
          write ( *, '(    "compiler version  = ", g0    )' ) c_version
          write ( *, '(    "compiler options  = ", g0    )' ) trim ( c_options )
          write ( *, '(    "execution command = ", g0, / )' ) trim ( cmd )
  
          write ( * , 100 ) 'default', sizeof ( default )
  
          write ( * , 100 ) 'int_8', sizeof ( int_8 )
          write ( * , 100 ) 'int_16', sizeof ( int_16 )
          write ( * , 100 ) 'int_32', sizeof ( int_32 )
          write ( * , 100 ) 'int_64', sizeof ( int_64 )
  
          write ( * , 100 ) 'int_a', sizeof ( int_a )
          write ( * , 100 ) 'int_b', sizeof ( int_b )
          write ( * , 100 ) 'int_c', sizeof ( int_c )
          write ( * , 100 ) 'int_d', sizeof ( int_d )
  
          write ( * , 110 ) 'aint', aint
          write ( * , 110 ) 'bint', bint
          write ( * , 110 ) 'cint', cint
          write ( * , 110 ) 'dint', dint
  
          write ( * , 110 ) 'selected_int_kind ( INT16 )', selected_int_kind ( INT16 )
  
    100   format ( "Number of bytes in type ", g0, " = ", g0 )
    110   format ( "Value of ", g0, " = ", g0 )
  
  end program bytes
  </code></pre>