nonzero lower bounds in arryas

Chris Torek chris at umcp-cs.UUCP
Mon Jun 2 17:21:14 AEST 1986


In article <2157 at mit-eddie.MIT.EDU> barmar at mit-eddie.UUCP (Barry
Margolin) writes:

>In article <900 at ttrdc.UUCP> levy at ttrdc.UUCP (Daniel R. Levy) writes:
>>By the way, this does raise a question in my mind about how the convention
>>of 1, not 0, being the lower bound subscript for an array is gotten around
>>efficiently in implementations of Fortran. [levy]

>In the case of one-dimensional arrays, of course, it can be handled at
>compile time. [barmar]

Actually, in all cases it can be handled at compile time, with what
is, as I recall, referred to as a virtual origin (did I get the name
right, John?).  For example, given the declaration

	var arr : array [1..3, 5..6, -8..7] of char;

and the assumption that we are to dispense with subscript checking,
find the address of arr[0, 0, 0], then use that as the `origin' of
the array, instead of the array name itself.  The idea is that the
correction factor for each subscript is a constant, and that it is
then multiplied by a constant and added to other constants ...
which of course gives a constant result.  Simply factor out the
constants, and then forget the origins!
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list