chris@umcp-cs.UUCP (Chris Torek) (06/02/86)
In article <2157@mit-eddie.MIT.EDU> barmar@mit-eddie.UUCP (Barry Margolin) writes: >In article <900@ttrdc.UUCP> levy@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@umcp-cs ARPA: chris@mimsy.umd.edu
franka@mmintl.UUCP (Frank Adams) (06/03/86)
>>>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, [Chis Torek] Not in the multidimensional case when one of the dimensions (other than the last) is a variable. However, every FORTRAN compiler I have worked with does do this simplification when possible. Frank Adams ihnp4!philabs!pwa-b!mmintl!franka Multimate International 52 Oakland Ave North E. Hartford, CT 06108
chris@umcp-cs.UUCP (Chris Torek) (06/05/86)
In article <1775@umcp-cs.UUCP> I wrote: >Actually, in all cases [nonzero lower bounds] can be handled at >compile time, with ... virtual origin[s]. As someone pointed out, this discussion originated with someone's `wish list' item of run-time subscript bounding a la FORTRAN's SUBROUTINE FOO(M, N, A) INTEGER M, N INTEGER A(M,N) declarations. In such cases virtual origins still work, but must be computed at run time, e.g., at entry to FOO above. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu