Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think.com!eplunix!mrn From: mrn@eplunix.UUCP (Mark R. Nilsen) Newsgroups: comp.sys.mac.programmer Subject: Re: Pascal deficiency? Message-ID: <991@eplunix.UUCP> Date: 17 Dec 90 18:59:42 GMT References: Organization: Eaton-Peabody Lab, Boston, MA Lines: 29 in article , aberno@questor.wimsey.bc.ca (Anthony Berno) says: > I was doing some speed checks on > array accessing today, and it occured to me that in doing something > like incrementing an entry by one, the computer was doing rather a > lot of work! > In Pascal getting to an array element with: MyArray[i] := Data; Has the computer taking the address of MyArray and adding (i * Sizeof(Data)). In C stepping through an array with: MyArray++ = Data; Has the computer taking the address of MyArray and incrementing by Sizeof(Data). In C you bypass an integer multiply. That is one of the nice things about C. You can of course still do it the slow way in C with MyArray[i] = Data, and the compiler will do the multiply. Think Pascal lets you do some pointer calculations but you have to do the size calculations yourself, in C the compiler will do them for you (in the case of ++). --Mark.