Fortran has five intrinsic data types:
character. Each of those types can be additionally characterized by a kind which defines internal representation of the type. For the three numeric types, it defines the precision and range, and for the other two, the specifics of storage representation.
The numeric types are based on number models with associated inquiry functions. These functions are important for portable numerical software:
Integer literal constants of the default kind take the form:
1 0 -999 32767 +10
Kind can be defined as a named constant. If the desired range is , the portable syntax for defining the appropriate kind,
integer, parameter :: two_bytes = selected_int_kind(4)
that allows subsequent definition of constants of the form:
two_bytes is the kind type parameter; it can also be an explicit default integer literal constant, like
but such use is non-portable.
kind function supplies the value of a kind type parameter:
range function supplies the actual decimal range (so the user must make the actual mapping to bytes):
data (initialization) statements, binary (
b), octal (
o) and hexcadecimal (
z) constants may be used (often informally referred to as “BOZ constants”):
b'01010101' o'01234567' z'10fa'
There are at least two real kinds—the default, and one with greater precision (this replaces
selected_real_kind functions returns the kind number for desired range and precision; for at least 9 decimal digits of precision and a range of to , it can be specified as:
integer, parameter :: long = selected_real_kind(9, 99)
and literals subsequently specified as:
Also, there are the intrinsic functions
kind(1.7_long) precision(1.7_long) range(1.7_long)
that give in turn the kind type value, the actual precision (here at least 9), and the actual range (here at least 99).
complex data type is built of two integer or real components:
There are only two basic values of logical constants:
.false.. Here, there may also be different kinds (to allow for packing into bits or bytes). Logicals don’t have their own kind inquiry functions, but use the kinds specified for
integers. The default
logical is the same that as of
kind function operates as expected:
The forms of literal constants for the
character data type are:
'A string' "Another" 'A "quote"' ''
where the last being an empty string. Different kinds are allowed (for example, to distinguish ASCII and UNICODE strings), but not widely supported by compilers. Again, the kind value is given by the