Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!munnari.oz.au!uniwa!vax7!nlewispn From: Lewis_P@cc.curtin.edu.au (Peter Lewis) Newsgroups: comp.sys.mac.programmer Subject: Re: Problems with THINK Pascal Message-ID: <6736.2792f672@cc.curtin.edu.au> Date: 15 Jan 91 04:32:49 GMT References: <1991Jan11.190458.7714@swift.cs.tcd.ie> Organization: Curtin University of Technology Lines: 88 In article <1991Jan11.190458.7714@swift.cs.tcd.ie>, david@swift.cs.tcd.ie writes: > I have just purchased a new version of THINK Pascal to run on a Mac II si, > and have encountered two problems when dealing with PACKED ARRAYs of BOOLEAN. > > setting A[0]:=TRUE corresponds to setting the byte value to 1, > ... > setting B[1]:=TRUE corresponds to setting the byte value to 2, Certainly does seem that way > ii. Assigning a boolean value based on the comparison of elements from packed > boolean data structures, will not always produce the correct result > VAR > RESULT: BOOLEAN; > LOGICAL1,LOGICAL2: PACKED ARRAY[0..7] OF BOOLEAN; > > RESULT:=LOGICAL1[3]=LOGICAL2[3]; > will produce the following results > LOGICAL[1] LOGICAL[2] RESULT > ---------- ---------- ------ > TRUE TRUE TRUE > TRUE FALSE TRUE !!! > FALSE TRUE FALSE > FALSE FALSE TRUE In fact, there is no problem with this assignment. The problem stems from the fact that the following code bool:=false; logical1[3]:=bool; does not work. In fact it clears a bit far away from logical1. The code generates this - CLR.B D6 ; bool:=false; MOVEQ #$03,D0 MOVE.W D0,D1 LSR.W #$3,D1 ; offset in bytes from the start of logical1 TST.B D6 BEQ.S ClrIt ADDI.W #-$108,D1 ; Ooops! BSET D0,$00(A5,D1.W) BRA.S Finish ClrIt BCLR D0,$00(A5,D1.W) ; where is the corresponding ADDI Finish So assigning a boolean variable to logical1[3] will work fine if the variable is true, but will fail if the boolean is false. > This problem can be solved by using an if statement > > IF LOGICAL1[3] = LOGICAL2[3] > THEN RESULT:=TRUE > ELSE RESULT:=FALSE; I suspect when you tested this, you put "LOGICAL1[3]:=true" and not for bool:=false to true do begin logical3[3]:=bool; as you probably did for the truth table. > I would like to know if I am missing something obvious, if there are any other > known problems in this area, etc. The only related problem I know of, is that this code - const s = 'hello'; begin writeln(s[2]); { will print random stuff } end. will fail if range checking is on. > David M. Abrahamson, > Dept. of Computer Science, > Trinity College, Dublin 2, Ireland. I suggest you leave packed arrays of booleans alone unless you are very careful! Fun fun fun, Peter. -- Disclaimer:Curtin & I have an agreement:Neither of us listen to either of us. *-------+---------+---------+---------+---------+---------+---------+-------* Internet: Lewis_P@cc.curtin.edu.au I Peter Lewis ACSnet: Lewis_P@cc.cut.oz.au I NCRPDA, Curtin University Bitnet: Lewis_P%cc.curtin.edu.au@cunyvm.bitnet I GPO Box U1987 UUCP: uunet!munnari.oz!cc.curtin.edu.au!Lewis_P I Perth, WA, 6001, AUSTRALIA Hack: ResEdit ResEdit 2.0b2, change CODE=5, 00091C: 4EBA 02A4 to 4E71 4E71