Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo Pascal - <b> const constants pp 48</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 CONST                            Constants                            pp 48


 Define:  A constant is a known value that is coded into the program
          Code Segment at compile time.

 Purpose: Provide a global value for program use.

 Notes:   Constants may be typed or untyped.
          They may be literal, named, or structured.

          A literal constant is one that represents a value such as 3.14159.
          A named constant represents a value by a label such as PI.
          A structured constant may be an array, record, set, or pointer.

          Named constants are preferred over literal constants as they are
          easier to change.  It is much easier to change the value of a named
          constant rather than search for every occurrence of a literal one.

          A simple or scalar constant is used by the compiler as a 'plug in'
          value at compile time.  A structured constant is an initialized
          data structure that resides in the Code Segment at run time.


 ----------------------------------------------------------------------------


 Named Constants:
       CONST
          PI         = 3.1415926536E+0         ;   { Real                   }
          Mile       = 5280                    ;   { Integer                }
          Boiling    = 212                     ;   { Untyped numeric        }
          Drive      = 'A'                     ;   { Untyped string or char }
          8087       = True                    ;   { Boolean                }
          Null       = ''                      ;   { Untyped string or char }


  Array Constant:
       CONST
          HexTable   : Array [0..15] of Char =
                       ('0','1','2','3','4','5','6','7',
                        '8','9','A','B','C','D','E','F');


  Set Constant:
       CONST
          Yes_Set    : Set of Char = ['Y','y']  ;  { Set of two values      }
          UpperCase  : Set of Char = ['A'..'Z'] ;  { Uppcase case letters   }
          WhiteSpace : Set of Char = [#9,#10,#12,#13,#32]


  Typed Constant:
       TYPE
          SuitType    = (Clubs, Diamonds, Hearts, Spades);
          RankType    = (Ace, Deuce, Three, Four, Five, Six,
                         Seven, Eight, Nine, Ten, Jack, Queen, King);
          Card        = Record                     { Constant type          }
                        Suit : SuitType;
                        Rank : RankType;
                        End;

       CONST
          AceOfSpades : Card       = (Suit : Spades; Rank : Ace);
          Drive       : Char       =     'A'      ;   { Typed Char          }
          Boiling     : Byte       =    212       ;   { Typed Byte          }
          Mile        : Integer    =   5280       ;   { Typed Integer       }
          StrVar      : String [5] = '12345'      ;   { Typed String [5]    }

See Also: Label Type Var

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson