Expressions - Operands
Operands can be any of the following:
Each operand has a type associated with it that determines what operators can apply to it.
For Integer constants, Real constants, Complex constants see Type declarations: basic types.
Character and string constants
String constants are specified by enclosing a string of characters in either single or double quotes. A string constant with N characters has the type:
ARRAY [0..N-1] OF CHAR
String constants with exactly one character are also compatible with the CHAR type.
String constants are compatible with ARRAYs that have an element type of CHAR.
Note: for ease of interfacing with operating systems and other languages, string constants are always followed in memory by a byte containing the NUL character (0 decimal).
A string constant with no characters (represented by two adjacent quotes, "") is allocated one byte and has the value NUL. If this string is passed to a procedure expecting an ARRAY OF CHAR, the upper bound will be zero, which indicates a string with one character. In this case, the one character is NUL.
You can use set, array and record constants in expressions using the same syntax for the value as used in constant declarations.
SET, ARRAY and RECORD value constructors
This creates a constant value from expressions that cannot be computed at compile time. A value constructor can only be used in expressions that are part of a statement.
SET, ARRAY and RECORD value constructors have the same syntax as SET, ARRAY and RECORD constants, however you can use non compile time values for any of the elements in the constructor.
If you use the BY keyword in an ARRAY value constructor, the BY repeat expression must still be a compile time constant.
A variable designator refers to the current value of a variable. The syntax of a variable designator is:
If the modulename is specified, the variablename exported from that module is used. Otherwise, the variablename is interpreted in the current scope.
[ field | subscript | dereference | subarray | coercion ]
The field qualifier is specified by:
The field qualifier can be applied to a variable designator that refers to a record type. The new designator refers to the field of the record named by the identifier.
The subscript qualifier is specified by:
The subscript qualifier can be applied to a variable designator that is an array type. The resulting designator refers to the component of the array selected by the index values specified by the expressions.
An expression of the form:
is equivalent to:
Dereference qualifierThe dereference qualifier is specified by:
The dereference qualifier can be applied to any designator that refers to a pointer type. The resulting designator refers to the object pointed to by the pointer variable.
A procedure designator is simply the name of the procedure. A procedure designator refers to the address of the procedure and can only be passed as a parameter or assigned to a procedure variable.
A procedure designator followed by parentheses is a function call. The procedure must be a function procedure; that is, its declaration must include a return type.
A function call is specified by:
The list of expressions are the actual parameters of the function. The actual parameters are matched in order with the formal parameters.
The requirements for the actual parameters depend on how the formal parameter was declared:
Formal parameter types are discussed in depth in the Procedures topic in this document.
The value of a function call is the value returned on the return statement in the function procedure.
You can force an expression to be interpreted as a type other than its usual type by using a type cast.
A type cast takes the following form:
The expression is evaluated, then forced to be interpreted as the type specified by TypeName. No conversion of data is done by type transfers. The raw data is interpreted as the new type. The CAST function is imported from the SYSTEM module.
This means that type transfers are dependent on the data representation used by an implementation, and are therefore not transportable.
For this reason, type conversion procedures are preferred when applicable. See the Standard Procedures chapter of this manual for information about type conversion procedures.
Type transfers from a shorter to a longer type are allowed, however a warning is generated because the excess bits are undefined.
The value written is 22, because the BITSET has bits 1, 2, and 4 set. When interpreted as a CARDINAL this makes the number 22.