Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!think!mit-eddie!barmar From: barmar@mit-eddie.MIT.EDU (Barry Margolin) Newsgroups: net.lang.c Subject: Re: C vs. FORTRAN (was: What should be added to C) Message-ID: <2157@mit-eddie.MIT.EDU> Date: Mon, 2-Jun-86 00:11:04 EDT Article-I.D.: mit-eddi.2157 Posted: Mon Jun 2 00:11:04 1986 Date-Received: Tue, 3-Jun-86 23:38:07 EDT References: <1594@ecsvax.UUCP> <853@bentley.UUCP> <1621@ecsvax.UUCP> <900@ttrdc.UUCP> Reply-To: barmar@mit-eddie.UUCP (Barry Margolin) Organization: MIT, EE/CS Computer Facilities, Cambridge, MA Lines: 33 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. In the case of one-dimensional arrays, of course, it can be handled at compile time. A good optimizer can also recognize the common patterns of looping over multidimensional arrays, so that the offset can be simply incrememented rather than requiring subscript calculations on each iteration (some of the earliest work on Fortran compilers involved this type of optimization). > It sounds like it is a royal, CPU- >wasting pain to have to subtract that pesky correction factor from the ag- >gregate subscript in coming up with an offset for the address of the array >element from the base of the array the way Fortran does, unless the computer >has a hardwired way of accessing an object in memory based on a base address >(base of the array), an offset (calculated from the subscripts), and a >correction factor (based on how the array was dimensioned) residing in regis- >ters and added together automatically. >I think I recall from days of yore in assembly language programming that >the IBM 360/370 architecture was set up to allow just this, not surprising >for a machine from the original inventors of Fortran. But what about other >machines, especially the more powerful (scalar) ones? Do they all share this >multiple-offset-addressing capability? (Not that this would be advantageous >in Fortran only; C could also use such a feature when accessing multiply- >dimensioned arrays of the type "array[][][]...".) I think many mainframes have such addressing modes. -- Barry Margolin ARPA: barmar@MIT-Multics UUCP: ..!genrad!mit-eddie!barmar