Carefuly read this, though it is not 100 percent duplicate:
Fortran: integer*4 vs integer(4) vs integer(kind=4) and
Fortran 90 kind parameter.
kind=8
is non-portable and will not work in some compilers and teaching it to beginners, which can be seen even in one Coursera course should be criminally prosecuted.
There are different compiler options with different effect. Ones promote all 4 byte reals or integers to 8 byte ones. Other set default kind to be 8. This breaks some standard assumptions about storage and about double precision
being able to hold more than the default kind. For example in gfortran:
-fdefault-real-8
sets the default real as 8 byte real. This is not completely the same as:
-freal-4-real-8
which promotes all 4 byte reals to 8 byte. You must be careful to understand the differences and generally using these options is not a very good practice.
The recommended solution is always the same, using a named constant:
integer, parameter :: rp = ...
and always using
real(rp) :: x
You can have more of these constants. Set the values of the constants according to the referenced question (real64
, kind(1.d0)
, selected_real_kind(...)
).