Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Help with casts Message-ID: <4828@goanna.cs.rmit.oz.au> Date: 26 Feb 91 09:46:06 GMT References: <1991Feb21.040145.8678@cec1.wustl.edu> <409@ceco.ceco.com> <1991Feb25.143544.11950@watdragon.waterloo.edu> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 27 In article <1991Feb25.143544.11950@watdragon.waterloo.edu>, dsebbo@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.