Node: or, Next: Ord, Previous: operator, Up: Reference

### or

#### Synopsis

         operator or (operand1, operand2: Boolean) = Result: Boolean;

or

         operator or (operand1, operand2: integer_type) = Result: integer_type;

or

         procedure or (var operand1: integer_type; operand2: integer_type);

#### Description

In GNU Pascal, `or` has three built-in meanings:

1. Logical “or” between two `Boolean`-type expressions. The result of the operation is of `Boolean` type.

   By default, `or` acts as a short-circuit operator in GPC: If the first operand is `True`, the second operand is not evaluated because the result is already known to be `True`. You can change this to complete evaluation using the `--no-short-circuit` command-line option or the `{$B+}` compiler directive.

2. Bitwise “or” between two integer-type expressions. The result is of the common integer type of both expressions.
3. Use as a “procedure”: `operand1` is “or”ed bitwise with `operand2`; the result is stored in `operand1`.

#### Conforming to

The logical `or` operator is defined in ISO 7185 Pascal.

According to ISO, you cannot rely on `or` being a short-circuit operator. On the other hand, GPC's default behaviour does not contradict the ISO standard. (See or_else.) However, since it seems to be a de-facto standard among ISO Pascal compilers to evaluate both operands of `or`, GPC switches to `--no-short-circuit` mode if one of the language dialect options selecting ISO Pascal, for instance `--extended-pascal`, is given. Use `--short-circuit` to override.

Use of `or` as a bitwise operator for integers is a Borland Pascal extension.

Use of `or` as a “procedure” is a GNU Pascal extension.

#### Example

         program OrDemo;
         var
           a, b, c: Integer;
         begin
           if (a = 0) or (b = 0) then  { logical `or' }
             c := 1
           else if (a or b) = 0 then  { bitwise `or' }
             c := 2
           else
             or (c, a)  { same as `c := c or a' }
         end.

Note the difference between the logical `or` and the bitwise `or`: When `a` is 2 and `b` is 4, then `a or b` is 6. Beware: `a or b = 0` happens to mean the same as `(a = 0) and (b = 0)`. (Note the `and`!)

Since bitwise `or` has a higher priority than the `=` operator, parentheses are needed in `if (a = 0) or (b = 0)` because otherwise `0 or b` would be calculated first, and the remainder would cause a parse error.

#### See also

Keywords, and, xor, Operators.