C vs. FORTRAN (was: What should be added to C)

Barry Margolin barmar at mit-eddie.MIT.EDU
Mon Jun 2 14:11:04 AEST 1986


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.

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 at MIT-Multics
    UUCP: ..!genrad!mit-eddie!barmar



More information about the Comp.lang.c mailing list