VMS Help
FORTRAN, Data, Constants

 *Conan The Librarian (sorry for the slow response - running on an old VAX)

  A constant is a fixed value.  The value of a constant can be a
  numeric value, a logical value, or a character string.  There are
  seven types of constants:  integer, real, complex, bit, logical,
  character, and Hollerith.  Bit and Hollerith constants have no data
  type; they assume a data type that conforms to the context in which
  they are used.

  1 - Bit

  A bit constant is a binary, octal, or hexadecimal constant.  You
  can use this type of constant wherever numeric constants are
  allowed and it assumes a numeric data type according to its
  context.

  A binary constant has the form:

    'c1c2c3...cn'B      c is a 0 or 1

  An octal constant has the form:

    'c1c2c3...cn'O      c is a digit in the range 0 - 7

  A hexadecimal constant has the form:

    'c1c2c3...cn'X      c is a digit in the range 0 - 9, or a letter
          or            in the range A - F, or a - f
    'c1c2c3...cn'Z

  Bit constants are "typeless" numeric constants.  They assume data
  types based on their usage, according to the following rules:

   o  When the constant is used with a binary operator, including the
      assignment operator, the data type of the constant is the data
      type of the other operand.

   o  When a specific data type is required, that type is assumed for
      the constant.

   o  When the constant is used as an actual argument, no data type
      is assumed; however, a length of 4 bytes is always used.

   o  When the constant is used in any other context, an INTEGER*4
      data type is assumed.

  Note that on VAX systems, the following example causes a
  data-typing problem:

     I = 80 * '01000000'X

  The quantity '01000000'X is typeless and assumes the data type of
  operand 80.  The compiler treats 80 as an INTEGER*2 quantity (since
  its value is within the range -32768 to 32767), and tries to
  convert '01000000'X to INTEGER*2.  Since '01000000'X is too large
  for the INTEGER*2 type, you get an error message.

  You can avoid this problem by giving the constant an INTEGER*4 type
  in a PARAMETER statement, as follows:

     INTEGER*4 K
     PARAMETER (K = '01000000'X)

  2 - Character

  A character constant is a string of printable ASCII characters
  enclosed by apostrophes.  A character constant has the form:

    'c1,c2,c3...cn'       c is a printable character.

  The length of the character constant is the number of characters
  between the apostrophes, except that two consecutive apostrophes
  represent a single apostrophe.  The length of a character constant
  must be in the range 1 to 2000.

  3 - Complex

  A complex constant consists of a pair of real or integer constants.
  The two constants are separated by a comma and enclosed in
  parentheses.  The first constant represents the real part of the
  number and the second constant represents the imaginary part.

  Compaq Fortran supports COMPLEX*8 and COMPLEX*16 complex constants.

  A COMPLEX*8 has the form:

   (c,c)             c is an integer or REAL*4 constant

  A COMPLEX*16 has the form:

   (c,c)             c is an integer, REAL*4, or REAL*8 constant
                     (at least one of the pair must be a
                                                REAL*8 constant)

  4 - Hollerith

  A Hollerith constant is a string of printable characters preceded
  by a character count and the letter H.  It is used only in numeric
  expressions and has the form:

    nHc1c2c3...cn

  n  Is an unsigned, nonzero integer constant stating the
     number of characters in the string (including tabs and spaces).

  c  Is a printable character.

  A Hollerith constant can be a string of 1 to 2000 characters and is
  stored as a byte string, one character per byte.

  Hollerith constants have no data type, but assume a numeric data
  type according to the context in which they are used.

  5 - Integer

  An integer constant is a whole number with no decimal point.  It
  can have a leading sign and is interpreted as a decimal number.  It
  has the form:

    snn               s  is an optional sign
                      nn is a string of decimal digits

  The value of the integer constant must be in the range -2147483648
  to 2147483647.

  You can use integer constants to assign values to data.  The
  integer data types have the following ranges:

    BYTE         Same range as LOGICAL*1 and INTEGER*1

    INTEGER*1    Signed integers: -128 to 127 (-2**7 to 2**7-1)
    (1 byte)     Unsigned integers: 0 to 255 (2**8-1)

    INTEGER*2    Signed integers: -32768 to 32767
    (2 bytes)                     (-2**15 to 2**15-1)
                 Unsigned integers: 0 to 65535 (2**16-1)

    INTEGER*4    Signed integers: -2147483648 to 2147483647
    (4 bytes)                          (-2**31 to 2**31-1)

  Integer constants in an octal form are preceded by a quotation mark
  and must use only the digits 0-7.

  6 - Logical

  The logical constants are .TRUE.  and .FALSE.

  7 - REAL_4

  A REAL*4 constant can be a basic real constant (with or without a
  decimal exponent) or an integer constant followed by a decimal
  exponent.  A basic real constant has one of these forms:

     s.nn                s is an optional sign
     snn.nn              nn is a string of decimal digits
     snn.

  A decimal exponent has the form:

     Esnn                s is an optional sign
                         nn is an integer constant

  8 - REAL_8

  A REAL*8 constant can be a basic real constant or an integer
  constant followed by a decimal exponent.  A decimal exponent has
  the form:

     Dsnn         s is an optional sign
                  nn is a string of decimal digits

  There are two implementations of the REAL*8 constant:  D_floating
  and G_floating.  G_floating requires the /G_FLOATING command
  qualifier.

  9 - REAL_16

  A REAL*16 constant can be a basic real constant or an integer
  constant followed by a decimal exponent.  A decimal exponent has
  the form:

     Qsnn              s is an optional sign
                       nn is a string of decimal digits
  Close     HLB-list     TLB-list     Help  

[legal] [privacy] [GNU] [policy] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.