2-3  DATA TYPES 
 ***************
 (Thanks to Craig Burley for the excellent comments)


 The star notation
 -----------------
 The 'star' (*n) notation is standard Fortran for character strings, 
 using the star notation for non-character (numeric) data-types is 
 common, but not standard Fortran, either FORTRAN 77 or Fortran 90. 

 The Fortran standards can't allow the star notation because they 
 must avoid any restriction on the internal representation of variables, 
 otherwise Fortran programs will not be portable to machines with 
 different architectures. 

 The number after the star in character strings is the number of
 "character storage units", whose size is purposely left undefined 
 and is never compared with the "numeric storage unit" used to 
 describe numeric types. The number of "character storage units" 
 is the number of characters in the string, not the number of bytes. 

 Almost all "English speaking" computers use one-byte representations
 for characters, so the number after the star coincide with the 
 number of bytes used in the internal representation. In the 
 non-standard use of the star notation for numeric data types, 
 the number after the star also denotes the number of bytes used.


 The basic data types
 --------------------
 The data types provided by a language have little to do with the 
 underlying machine, there were perfectly usable Fortran compilers 
 on 8-bit computers, which simulated 32-bit floating point hardware.

 The basic data types of FORTRAN 77 are: integers, floating-point 
 numbers of two kinds (REAL and DOUBLE PRECISION), logicals and 
 character strings. 

 In FORTRAN 77, the only allowed method of creating compound data 
 types out of the basic types is forming arrays.


 Character strings
 -----------------
 The term 'character' became a little vague, due to widespread
 confusion between the objects themselves and their representations.

 A character is a graphic sign (glyph) that may be represented 
 differently in different representation schemes developed and
 used on different machines. 

 Individual characters (CHARACTER*1) are always represented in 
 practise as small integers, usually in the range 0-255 so they 
 can be stored in one byte (see Appendix B and the terminals and 
 printers chapter).

 The exceptions to the 'one byte per character rule' are:

    1) Unicode systems - characters are consistently 
       16-bits per character.

    2) asian language systems - the number of bytes 
       per character is variable.

 Because characters are represented, in practice, always as small 
 integers, and representations are what computers use and work with, 
 people sometimes tend to think that the integer representation is 
 the primary entity.

 You will often hear people referring to characters as if the graphic 
 sign is assigned to the representation, e.g. 'character 32 is SPACE',
 instead of 'SPACE is represented by 32 in the ASCII scheme'.

 In most computers the translation between characters and numbers 
 is made according to the ASCII scheme. There are other schemes like 
 EBCDIC on IBM computers - in that scheme the decimal digits and the 
 letters doesn't have successive values (see Appendix B).

 Different extensions of the ASCII scheme are discussed in the
 chapter on terminals and printers. 

 Individual characters can be combined to form character arrays and 
 character strings.


 BYTE
 ----
 A NONSTANDARD fortran data type, equivalent to C 'signed char'.

 Can be thought of as a small subtype of INTEGER, formally equivalent 
 to LOGICAL*1, which is also nonstandard fortran.

 Should be used only if you have to do fast byte manipulations on data.

 Size:          1 byte (8 bits)
 Value range:   -128 to 127.


 INTEGER
 -------
 The data given here is "typical", but not standard or ubiquitous.

 the standard INTEGER data type was implemented as INTEGER*2 on old 
 16 bit machines, it is now usually INTEGER*4, but on the new 64 bit 
 machines (and some older ones) it may be an INTEGER*8.

 For more information on integer representations see the chapter 
 on integers.

 FORTRAN integer types are signed: 


    INTEGER*2 (non-standard)
    ------------------------
    Size:           2 bytes (16 bits, bit 15 = sign)
    Value range:    -32768 to 32767


    INTEGER*4 
    ---------
    Size:           4 bytes (32 bits, bit 31 = sign)
    Value range:    -2147483648 to 2147483647

    INTEGER*4 can be thought of as an extended INTEGER*2 - 
    if the value lies in the INTEGER*2 range, then the first 
    (little-endian machine) or last (big-endian machine) two 
    bytes can be referenced as an INTEGER*2


    INTEGER*8
    ---------
    Similar to INTEGER*4 but with larger range.
    Found on 64 bit machines and on 32-bit machines such as SPARC. 


 REAL and DOUBLE PRECISION
 -------------------------
 The standard REAL and DOUBLE PRECISION data types may be implemented
 differently on different machines.

 Usually REAL is 4 bytes long and DOUBLE precision is 8 bytes long,
 on CRAYs they are 8 and 16 bytes long respectively, but not all bytes
 are used.

 See the section on Floating-Point Numbers for an elementary 
 introduction to the subject and information on various aspects.


 LOGICAL
 -------
 The FORTRAN standard requires logical variables to be the same size 
 as INTEGER/REAL variables (see the chapter on memory management) 
 although only one bit is really needed to implement this type.

 The values used to implement the logical constants .TRUE. and 
 .FALSE. differ:

              |    VMS     |    Sun    |   IRIX    |
   -----------|------------|-----------|-----------|-----------
    .TRUE.    |    -1      |     1     |     1     |
   -----------|------------|-----------|-----------|-----------
    .FALSE.   |     0      |     0     |     0     |
   -----------|------------|-----------|-----------|-----------

 Unix machines naturally adopted the C convention, VMS has a seemingly
 strange value for .TRUE., however on a closer look you will see that 
 if .FALSE. is "all bits 0", .TRUE. should be "all bits 1", in two's
 complement signed integers the number with all bits set to 1 is -1.


Return to contents page