[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.1.3 Constant Declaration

A constant declaration has the following look:

 
const
  constant identifier = constant expression;
  ...
  constant identifier = constant expression;

A constant declaration part starts with the reserved word const. It declares a constant identifier which is defined by constant expression. This expression has to be evaluatable during compilation time, i.e. it can include numbers, parentheses, predefined operators, sets and type casts (the last, however, is a Borland extension). In ISO-7185 Pascal, constant expression must be a constant or a set. All Pascal Dialects but ISO-Pascal allow the use of these intrinsic functions in constant expression:

section 9.1 Abs, section 9.236 Round, section 9.282 Trunc, section 9.41 Chr, section 9.181 Ord, section 9.133 Length, section 9.201 Pred, section 9.271 Succ, section 9.257 SizeOf, section 9.176 Odd.

In Borland Pascal, in the constant declaration part variables can be declared as well, which are given an initial value. These variables are called "typed constants". It is good style to avoid this use, especially since Extended Pascal and GNU Pascal allow to initialize a variable in variable declaration part or give a type a preset value on declaration.

 
const
  FiveFoo      = 5;
  StringFoo    = 'string constant';
  AlphabetSize = Ord ('Z') - Ord ('A') + 1;

type PInteger = ^Integer; { Define a pointer to an Integer }

const { Constant which holds a pointer to an Integer at address 1234 } AddressFoo = PInteger (1234);

See also

section 8.1.6.4 Subroutine Parameter List Declaration


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Frank Heckenbach on May, 10 2002 using texi2html