I\'m trying to learn Fortran and I\'m seeing a lot of different definitions being passed around and I\'m wondering if they\'re trying to accomplish the same thing. What is t
Just one more explicit explanation what the kind is. The compiler has a table of different numerical types. All integer types are different kinds of the basic type -- integer
. Let's say the compiler has 1 byte, 2 byte, 4 byte, 8 byte and 16 byte integer
(or real
) kinds. In the table the compiler has an index to each of this kind -- this index is the kind number.
Many compilers choose this numbering:
kind number number of bytes
1 1
2 2
4 4
8 8
16 16
But they can choose any other numbering. One of the obvious possibilities is
kind number number of bytes
1 1
2 2
3 4
4 8
5 16
There are indeed compilers (at least g77 and NAG) which choose this approach. There are also options to change this. Therefore kind
numbers are not portable integer(kind=4)
or integer(4)
means a 4 byte integer or a 8-bytes integer depending on the compiler.
integer*4
is portable in the sense it always means 4 bytes. But on the other hand it is not portable because it has never been part of any standard. Programs using this notation are not valid Fortran 77, 90 or any other Fortran.
To see the right options how to set the kind numbers see M.S.B.'s answer.
The same concept holds for real
data types. See Fortran 90 kind parameter (the mataap's answer).