Path: utzoo!mnetor!uunet!steinmetz!ge-dab!codas!pdn!alan From: alan@pdn.UUCP (Alan Lovejoy) Newsgroups: comp.lang.modula2 Subject: Re: 0-based/1-based arrays Message-ID: <2597@pdn.UUCP> Date: 21 Mar 88 17:14:11 GMT References: <7161@sol.ARPA> <2740@mmintl.UUCP> <4343@june.cs.washington.edu> <8496@reed.UUCP> Reply-To: alan@pdn.UUCP (0000-Alan Lovejoy) Organization: Paradyne Corporation, Largo, Florida Lines: 22 In article <8496@reed.UUCP> douglas@reed.UUCP (P Douglas Reeder) writes: >I like being able to make the lower bound of an array whichever I prefer >and is the sensible one. Allowing this requires only a trivial addition to >array element evaluation: the lower bound is subtracted from the index first. That's way too complicated. The right way is to bias the base address of the array so that (Rn, Dn*ElementSize) points to the first element of the array when Dn's value is the lower index bound. Thus for 'a: ARRAY [m..n] OF Element', the compiler's (linker's) internal base address for the array 'a' would be ADR(firstElement) - (m * TSIZE(Element)) so that for positive m the base address is less than the address of the first element by m * TSIZE(Element) size units, and for negative m it is greater than the address of the first element by that amount. This is just removing an invariant computation from run-time to compile-time where it belongs. --alann@pdn