Ordinary constants declarations are constructed using an identifier name followed by an ”=” token, and followed by an optional expression consisting of legal combinations of numbers, characters, boolean values or enumerated values as appropriate. The following syntax diagram shows how to construct a legal declaration of an ordinary constant.
_________________________________________________________________________________________________________
Constant declaration
___________________________________________________________________
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, pi, int, trunc, round, frac, odd can be used, however. For more information on expressions, see chapter 12, page 534.
When a previously declared ordinary constant is used in the code, the compiler will insert the actual value of the constant instead of the constant name. That is, the following 2 pieces of code are entirely equivalent:
The above will produce the same code as if one had written:
Only constants of the following types can be declared:
The following are all valid constant declarations:
Assigning a value to an ordinary constant is not permitted. Thus, given the previous declaration, the following will result in a compiler error:
For string constants, the type of the string is dependent on some compiler switches. If a specific type is desired, a typed constant should be used, as explained in the following section.
Prior to version 1.9, Free Pascal did not correctly support 64-bit constants. As of version 1.9, 64-bit constants can be specified.