fpt and WinFPT Reference Manual - Command-line Commands
| SimCon Home | Ref Manual Home |
Kinds or Sizes ?
Most Fortran compilers support (at least) logical and integer objects which occupy 1, 2, 4 and 8 bytes, real objects which occupy 4 and 8 bytes, and complex objects which occupy 8 and 16 bytes. The Fortran 90 and later standards handle the different numeric data sizes as different kinds. Typically, a 1-byte integer is declared as INTEGER(KIND=1), a 2-byte integer is declared as INTEGER(KIND=2), a 4-byte integer as INTEGER(KIND=4) and so on.
However, the numbers which are used to specify the kinds are not specified in the Fortran standard. They are processor-specific, and the compiler writers are free to choose the set of integers to represent them.
All but one of the Fortran 90 (and later) compilers known to the author use the number of bytes which a logical, integer or real number occupy as the kind number (Complex objects have the kinds of the corresponding real objects). Unfortunately, the exception, Silverfrost (Formerly Salford Software) FTN95, is one of the best diagnostic compilers currently available. FTN95 numbers the available kinds for each data type starting from 1. A 4-byte real object, for example, is declared as REAL(KIND=1). Code which uses kind numbers is not portable. The kinds must be represented by Fortran parameters defined in a Fortran module or include file which is specific to the compiler in use.
Fortran 90 provides two intrinsic functions, SELECTED_INT_KIND and SELECTED_REAL_KIND which allow the kind numbers to be derived from the range or precision of an object. There is no corresponding function for logical objects, and the solution is therefore incomplete. Also, the authors (and probably others) are carrying out research on real number formats where the precision varies with the absolute magnitude of the number. In these numbers there is no one-to-one matching of kind with precision.
An advantage of the Fortran 90 kind syntax is that it provides a convenient way to write literal values (e.g. numbers) of a specified kind. A 2-byte integer value, for example, may be written as 300_ki2, where ki2 is the parameter for the 2-byte integer on the current system.
Before the Fortran 90 standard, extended Fortran 77 compilers declared different numeric data sizes by appending "*n" where n is the data size, to the type keyword. Thus, 4-byte integer objects are declared INTEGER*4. Every extended Fortran 77, Fortran 90 and later compiler known to the authors accepts data size specifications in this format. Software Validation Ltd. holds a large library of Fortran codes. Most of these codes use data sizes instead of kinds.
Note that the extended FORTRAN 77 data size convention does not provide a convenient way to write logical and integer literal values of non-default sizes. Real values may be written by using the exponent character to specify the size. Thus, a 4-byte value is written as 1.0E0 and an 8-byte value as 1.0D0.
The advantages of using kinds
The disadvantages of using kinds
The advantages of using data sizes
The disadvantages of using data sizes
The fpt Commands
The commands CHANGE KINDS TO SIZES and CHANGE DATA SIZES TO KINDS change declaration statements between the two formats. They do not change the handling of literal values. The command SHOW KINDS shows the kinds and data sizes used in a program and the numbers of declarations and literal values of each kind with and without kind specifications.
Copyright ©1995 to 2024 Software Validation Ltd. All rights reserved.