Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-lcc!ames!ucsd!rutgers!cmcl2!adm!xadmx!abcscnuk%CSUNA.UUCP@cunyvm.cuny.edu From: abcscnuk%CSUNA.UUCP@cunyvm.cuny.edu (Naoto Kimura) Newsgroups: comp.lang.pascal Subject: Re: Re^2: Control variables in FOR loops Message-ID: <18192@adm.BRL.MIL> Date: 25 Jan 89 03:36:07 GMT Sender: news@adm.BRL.MIL Lines: 43 In article <449@ambone.UUCP> leif@ambone.UUCP (Leif Andrew Rump) writes: >dik@cwi.nl (Dik T. Winter) writes: >>In article <00056@meph.UUCP> gsarff@meph.UUCP (Gary Sarff) writes: >> > In article <4267@okstate.UUCP> garnett@a.cs.okstate.edu (John Garnett) >> > >Isn't it also true that the value of 'i' will be undefined following the >> > >termination of the loop contained in procedure 'barf'? >> > >> > Depends on how the compiler makes 'i' undefined, if there is some way to >> > put a NaN (not a number) in i for example. >>But a compiler is not required to take action to make 'i' undefined. >>Undefined is just that: the standard does not predict the value present > >It will ease debugging if the runtime system is able to detect 'NaN'. >A lot of computers use two complement meaning (in a 16 bit >environment) that the range goes from -32768 to 32767. Use -32768 as >'Nan' and you have a 'normal' range -32767 to 32767... > > Leif Andrew Rump, AmbraSoft A/S, Roejelskaer 15, DK-2840 Holte (Denmark) > UUCP: leif@ambone.dk, phone: +45 2424 111, touch phone: +45 422 817 + 313 > > > > > Why are tall Irish girls with red hair so wonderful ? ? ? < < < If you turn on range checking, -32768 was 'NaN' in 3.0. All TP has to do is put that value into the index variable once the loop is exited. But it would only detect the problem when range checking was turned on. I'm not sure what 4.0 and 5.0 say about -32768 though (haven't tried it yet). I ran into the -32768 illegal integer value accidentally with 3.0 when I was trying to allocate 64Kbyte arrays. When I tried to access the 32768th element by using -32768 as the index, my program crashed. Turning off the range checking "fixed" the problem. Finally decided to screw trying to allocate 64Kbyte arrays (went and allocated the array as 2 32K byte arrays), since I could really only allocate 64K-1 byte sized arrays, and didn't want to bother fiddling with the memory allocation routines to make sure that I wasn't doing screwy things (like modify a 1-byte sized variable that might follow the array in memory) when I tried to access the 64Kth byte. //-n-\\ Naoto Kimura _____---=======---_____ (csun!csuna!abcscnuk) ====____\ /.. ..\ /____==== // ---\__O__/--- \\ Enterprise... Surrender or we'll \_\ /_/ send back your *&^$% tribbles !!