next up previous contents index search.gif
Next: 2.2 Typed constants Up: 2. Constants Previous: 2. Constants

2.1 Ordinary constants

Ordinary constants declarations are no different from the Turbo Pascal or Delphi implementation.

Constant declaration

\begin{syntdiag}\setlength {\sdmidskip}{.5em}\sffamily\sloppy \synt{constant\ de...
...
\synt{identifier} \lit*= \synt{expression} \lit*; \\
\end{rep} \end{syntdiag}
The compiler must be able to evaluate the expression in a constant declaration at compile time. This means that most of the functions in the Run-Time library cannot be used in a constant declaration. Operators such as +, -, *, /, not, and, or, div(), mod(), ord(), chr(), sizeof can be used, however. For more information on expressions, You can only declare constants of the following types: Ordinal types, Real types, Char, and String. The following are all valid constant declarations:

Const
  e = 2.7182818;  { Real type constant. }
  a = 2;          { Integer type constant. }
  c = '4';        { Character type constant. }
  s = 'This is a constant string'; {String type constant.}
  s = chr(32)
  ls = SizeOf(Longint);
Assigning a value to a constant is not permitted. Thus, given the previous declaration, the following will result in a compiler error:

  s := 'some other string';


root
1999-06-10