HP Pascal/iX Reference Manual (31502-90022)

5:- 11
Example
TYPE
answer = (yes, no, maybe);
VAR
pagecount,
linecount,
charcount: integer; { Standard identifier. }
whats_the: answer; { User-declared identifier. }
album : RECORD { Data type. }
speed: (lp, for5, sev8);
price: real;
name : string[20];
END;
Side-Effects
A
side-effect
is the modification by a procedure or function of a
variable that is global or nonlocal in scope to the procedure or
function. If a local variable is declared using the same identifier as a
global variable, the local variable may be modified without affecting the
global variable.
Example
PROGRAM show_effects(output);
VAR
i,j: integer; { Global variables }
PROCEDURE oops(i : integer); { i is local to the procedure }
BEGIN
IF i > 0 THEN j := j - 1; { j is a global variable }
END;
BEGIN
i := 2;
j := 3;
oops(i);
IF i = j THEN writeln('There was a side effect.');
END.
Output:
There was a side effect.
NOTE Side effect modifications may cause an optimizer to be more
conservative in its choices for code improvement, thereby
decreasing execution performance.