| Fortran Language Reference Manual, Volume 1 - S-3692-51 | ||
|---|---|---|
| Prev Section | Chapter 4. Data Types | Next Section |
Knowing exactly what is meant by type in Fortran becomes more important now that you can define types and type aliases in addition to the intrinsic types. A data type provides a means to categorize data and determine which operations can be applied to the data to get desired results. The following exist for each data type:
A name
A set of values
A set of operations
A form for constants of the intrinsic types and constructors for derived types
Each of the intrinsic types has a name supplied by the standard. The names of derived types must be supplied in type definitions. The name of the type is used to declare entities of the type unless the programmer chooses to let the processor determine the type of an entity implicitly by the first character of its name. Chapter 5, describes declarations and implicit typing.
Each type has a set of valid values. The logical type has only two values: true and false. The integer type has a set of integral numeric values that can be positive, negative, or zero. For complex or derived types, the set of valid values is the set of all combinations of the values of the individual components.
The kind of an intrinsic type determines the set of valid values for that type and kind. For example, there is more than one integer data type: the default type and shorter integer types. The shorter integer types have values that are a subset of the default integer values. The kind of a type is referred to as a kind parameter or kind type parameter of the type. The character data type has a length parameter as well as a kind parameter. The length parameter specifies the number of characters in an object, and this determines the valid values for a particular character object. Derived types do not have parameters, even though their components may.
For each of the intrinsic data types, a set of operations with corresponding operators is provided by the language. These are described in Chapter 7.
You can specify new operators and define operations for the new operators. The form of a new operator is an alphabetic name of your choice delimited by periods. These new operators are analogous to intrinsic operators such as .GT., .AND., and .NEQV.. For example, you might specify and define the operations .PLUS., .REMAINDER., and .REVERSE.. In defining the operation, the types of allowable operands must be specified. Such new operations can apply to objects of intrinsic type and in these cases extend the set of operations for the type. You would more frequently be defining operations for objects of derived type.
You cannot redefine an intrinsic operation, but you can define meanings for intrinsic operator symbols when at least one operand is not of an intrinsic type or for intrinsic operands for which the intrinsic operation does not apply. For example, consider the expression A + B. If both A and B are of numeric type, the operation is defined intrinsically and cannot be redefined. However, if either A or B is of derived type or nonnumeric type, the plus operation between A and B is not defined intrinsically, and you can provide a meaning for the operation. New operations are defined by functions with the OPERATOR interface. These are described in the Fortran Language Reference Manual, Volume 2.
Assignment is defined intrinsically for each intrinsic and derived type. Structure assignment is component-by-component intrinsic or pointer assignment, though this can be replaced by a defined assignment. No other intrinsically defined assignment, including array assignment, can be redefined. Beyond this, any assignment between objects of different type may be defined with the ASSIGNMENT interface as described in the Fortran Language Reference Manual, Volume 2.
The language specifies the syntactic forms for literal constants of each of the intrinsic types. Syntactic mechanisms (called derived-type constructors) specify derived-type values. As shown in Figure 4-2, the form indicates both the type and a particular member of the set of valid values for the type. Type aliases are treated in the same manner.
If a constant is not of default kind, some indication of its kind must be included in its syntactic form. This form is the default literal constant separated from the kind value by an underscore. Kind specifications follow integer, real, and logical values. Kinds are known to the Cray Fortran Compiler as integer values, but if a program is to be portable, the actual numbers should not be used because the kind values depend on the processor. Instead, a kind value should be assigned to a named constant, and you should use the name.
In the following examples, DOUBLE and HIGH are named constants for kind values:
| Real | 1.3141592653589_DOUBLE | |
| Complex | (1.75963_HIGH, -2.0) |
The kind of a complex constant is determined by the kind of its parts. Section 4.3.3.3, describes the form for complex literal constants.
| Prev Section | Table of Contents | Title Page | Index | Next Section |
| Data Types | Up one level | Intrinsic Data Types |