Help with casts

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Tue Feb 26 20:46:06 AEST 1991


In article <1991Feb25.143544.11950 at watdragon.waterloo.edu>, dsebbo at dahlia.uwaterloo.ca (David Ebbo) writes:
> No.  In Pascal, you can use any integer variable as a for loop index, and it
> can be referenced outside the loop.

There are three claims involved in this sentence, and all of them are false.
(1) Pascal index variables need not be integer variables; they may be of
    any discrete type (integer, enumeration, subrange of either).
(2) It is not the case that *any* variable of an appropriate type may be
    used, only a variable local to the current block may be used.
	program xx; var i: integer;
	procedure p; begin for i := 1 to 2 do ...
    is *illegal* because 'i' is not local to 'p'.
(3) The value of an index variable is *not* defined after a 'for' loop.
    One Pascal compiler I've used stuffed a special value into index
    variables after a loop was exited, which value caused a trap if you
    tried to fetch it (B6700 fans: it was a Tag 6 word).

The Pascal standard is clear on this.  Some Pascal system may not
check (2) and/or (3), but that's like a C system not trapping attempts
to dereference NULL, undefined behaviour not allowed in a standard-
conforming program is undefined behaviour.

Surely C can stand on its own merits without making false claims about
another programming notation?

-- 
The purpose of advertising is to destroy the freedom of the market.



More information about the Comp.lang.c mailing list