The goto statement, Uninitialized variables – HP SunSoft Pascal 4.0 User Manual

Page 240

Advertising
background image

216

Pascal 4.0 User’s Guide

9

A statement is considered to be reachable if there is a potential path of control,
even if it cannot be taken. Thus, no diagnostic is produced for the statement:

The

goto

Statement

Pascal detects and produces an error message about

goto

statements that

transfer control into structured statements—for example,

for

and

while

. It

does not allow such jumps, nor does it allow branching from the

then

part of

an

if

statement into the

else

part. Such checks are made only within the

body of a single procedure or function.

Uninitialized Variables

Pascal does not necessarily set variables to an initial value unless you explicitly
request that with the

–Z

option. The exception is

static

variables, which are

guaranteed to be initialized with zero values.

Because variable use is not tracked across separate compilation units,

pc

does

nothing about uninitialized or unused variables in global scope, that is, in the
main program. However,

pc

checks variables with local scope—those declared

in procedures and functions, to make sure they are initialized before being
used.

pc

flags uninitialized variables with a warning message.

Unused Variables, Constants, Types, Labels, and Routines

If you declare a variable, constant, type, procedure, or function in local scope
but never use it, Pascal gives you a warning message. It does not do this for
items declared in global scope because you can use the items in a separately
compiled unit.

This error message is
generated when you compile

unreached.p

.

hostname% pc unreached.p

Tue Feb 14 14:21:03 1995 unreached.p:

w 18630 line 8 - Unreachable statement

if false then

writeln('Impossible!')

Advertising