Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!sun-barr!cs.utexas.edu!asuvax!stjhmc!p12.f56.n114.z1.fidonet.org!Chris.Gehlker From: Chris.Gehlker@p12.f56.n114.z1.fidonet.org (Chris Gehlker) Newsgroups: comp.sys.mac.programmer Subject: Pascal deficiency? Message-ID: <33176.27759EC3@stjhmc.fidonet.org> Date: 24 Dec 90 06:20:33 GMT Sender: ufgate@stjhmc.fidonet.org (newsout1.26) Organization: FidoNet node 1:114/56.12 - AZ MAC UG, Phoenix AZ Lines: 44 AB> I generally prefer Pascal programming, but I have come up against AB> what seems like a real deficiency in the language. I never really AB> thought about it before, but there does not seem to be any equivalent AB> to the ++ or -- operator in Pascal. I was doing some speed checks AB> on array accessing today, and it occured to me that in doing AB> something like incrementing an entry by one, the computer was AB> doing rather a lot of work! AB> Either there is no way to do a quick increment in Pascal, or AB> I'm missing something in my knowledge, or I'm wrong about the AB> speed difference between things like ++(variable) and (variable):=(variable)+1 You are right about the loss of efficiency in accessing arrays but wrong about the source of the inefficiency. Variable := Variable +1 or Variable := Succ(variable) will generate exactly the same code as variable++, namely a addq.x #1,Dx. Where Pascal falls down is in address arthmetic: for i := 1 to rows do for j := 1 to columns do thearray[i,j] := something; will generate a run time multiply to each time through the inner loop to figure out the offset from the start of the array. On the Mac you can work around this by writing something like: Type elementPtr = ^integer; var theElement, arrayStart:longint; ... arrayStart := longint(@thearray[1,1]); theElement := 0 while theElement <= longint(@theArray[rows,columns]) do begin elementPtr(arrayStart + theElement)^ := something; theElement := theElement + sizeof(integer) end; This gives a big speedup at the cost of clarity and portability. -- Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!56.12!Chris.Gehlker Internet: Chris.Gehlker@p12.f56.n114.z1.fidonet.org