[comp.sys.apollo] The wonderful Pascal compiler...

derstad@CIM-VAX.HONEYWELL.COM ("DAVE ERSTAD") (11/15/90)

To elaborate on Jim's comments (in hopefully a friendlier fashion :-))
on the null pointer de-referencing, it is important to recognize that
Pascal, unlike C, does not specify order of expression evaluation (unless
this changed in the ISO standard, which I doubt).

For example, the Pascal code
   if (exprA) or (exprB)
may have either exprA or exprB evaluated first.  A compiler may choose
to do one or the other consistently; do the more efficient one; or
choose one based on the phase of the moon and be "correct".

Likewise, with
   if (exprA) and (exprB)
a compiler may choose to evaluate both expressions even if the first one
it evaluates is false.   In fact, it MUST evaluate both when there
is the potential for side effects.

C, by contrast, guarantees both order of evaluation and short
circuiting.  C supporters argue this is good, pointing to examples
like your code.  Detractors would argue this makes code more
difficult to maintain. 

So, in short, Apollo'
s compilers are not to blame (this time).

BTW, there are Domain pascal extensions to specify order
of evaluation (or else; and then), but I wouldn't 
recommend them as they are non-standard.

Dave Erstad
DERSTAD@cim-vax.honeywell.com
Honeywell SSEC

dhandly@hpcllz2.HP.COM (Dennis Handly) (11/15/90)

>/ derstad@CIM-VAX.HONEYWELL.COM ("DAVE ERSTAD") /  8:45 am  Nov 14, 1990 /

>For example, the Pascal code >   if (exprA) or (exprB)
>may have either exprA or exprB evaluated first.  A compiler may choose
>to do one or the other ...
>Likewise, with               >   if (exprA) and (exprB)
>a compiler may choose to evaluate both expressions even if the first one
>it evaluates is false.   In fact, it MUST evaluate both when there
>is the potential for side effects.

The last sentence conflicts with what you have/don't have for OR.  I would 
GUESS the standard says nothing about side-effects.  So a compiler doesn't
have to evaluate both operands for both AND and OR.  I'm pretty sure the
ANSI tests attempt to figure out what the compiler does and then puts that
on the report.  (I.e. for information only.)

(Not that the following helps, provided for information only.)
HP-UX's 600, 800 and other Pascals provides an option $partial_eval$.
The default is on.

The 85 COBOL ANSI standard states that a compiler must do partial evaluation.
It appears that both C and COBOL have standardized this useful feature.
(I'm not sure how they would write a test what would detect the violation,
except to index out of bounds?)