It is probably a good idea to use an odd number for the string size declaration so that the resulting array contains an even number of elements. This permits alignment of strings on long word boundaries*1. Since
Note that the string value need not fill the declared size. The EOS character signals the end of the string. This is in contrast to Fortran strings, which do not include a terminator character and thus have an implicit size equal to the declared size and are padded with trailing blanks to the string length. Rather, SPP strings are practically identical to the concept of strings in C. Therefore, it is not possible to call a Fortran subroutine directly that expects a string in the calling sequence. However, there are procedures that convert between SPP and Fortran strings. (See "Calling Fortran Subprograms" on page 38). Note that in most procedures that take a string argument, there is also an argument that specifies the maximum string size. See Chapter 2 for specific library procedures.
Generated with CERN WebMaker
Table 1.6: Data Types.
Note that the size of the variable depends on its hardware implementation which in turn depends on the combination of the Fortran compiler and the host operating system. For example, in VAX Fortran, short integers are implemented as INTEGER*2
, including char
and strings (char
arrays), and long integers are implemented as INTEGER*4
, which is the same size (four bytes) as INTEGER
, by default. In addition to the seven primitive data types, the SPP language provides the abstract type pointer. The SPP language makes no distinction between pointers to different types of objects, unlike more strongly typed languages such as C. The extern
type is also available to declare a function as a variable, as in the Fortran EXTERNAL
statement. Integer
SPP has three signed integer data types. There is no byte or unsigned integer data type.
INTEGER
declaration.int
. Character
The char data type belongs to the family of integer data types, i.e., a char variable or array behaves like an integer variable or array. The char and short data types are signed integers (i.e., they may take on negative values). String
A string is an array of type char terminated by an end of string character (EOS). Strings may contain only character data (values 0 through 127 decimal), and must be delimited by EOS. A character string may be declared in either of two ways, depending on whether initialization is desired:
char input_file[SZ_FNAME]
string legal_codes "efgdox"
char x[15]
The preprocessor automatically adds one to the declared array size, to allow space for the EOS marker. However, the space used by the EOS marker is not considered part of the string. Thus, the char array x[15] will contain 16 elements, space for up to 15 characters, plus the EOS marker. char
is implemented as Fortran INTEGER
, whose size is usually four bytes, sometimes referred to as a long word. Access to memory is usually more efficient if the variables are placed matching the addressable pieces Floating point
Floating point variables may be single precision (real), double precision (double), or complex (complex) and behave as the equivalent Fortran floating point variables.
REAL
data type.DOUBLE PRECISION
data type.COMPLEX
data type. Boolean
The only permissible values for a boolean variable are true and false. They are used as flag variables or used in test expressions of constructs such as if and while. Note the distinction between boolean variables and the integer constant parameters YES and NO; the latter are sometimes used as flags. Pointer
Pointers are used to reference dynamically allocated memory. See "Memory Allocation -- memio" on page 53 for a more complete discussion of dynamically allocated memory. More abstractly, pointers may be used to reference "structures," allocated memory with a particular arrangement of variables of differing data types and having a specific structure in memory.