[Numpy-discussion] C vs. Fortran order -- misleading documentation?

David Cournapeau cournape@gmail....
Wed Jun 9 04:54:18 CDT 2010

On Wed, Jun 9, 2010 at 4:16 PM, Francesc Alted <faltet@pytables.org> wrote:
> A Tuesday 08 June 2010 23:34:09 Anne Archibald escrigué:
>> > But the issue isn't one of efficiency, it's merely an arbitrarily chosen
>> > convention.  (Does anyone know the history of the choices for FORTRAN and
>> > C, esp. why K&R chose the opposite of what was already in common usage in
>> > FORTRAN?  Just curious?)
>> This is speculation, not knowledge, but it's worth pointing out that
>> there are actually two ways to represent a multidimensional array in
>> C: as a block of memory with appropriate type definitions, or as an
>> array of pointers to subarrays. This latter approach is generally not
>> used for numerical work, but is potentially useful for other
>> applications. More relevantly, it already has a natural syntax;
>> a[2][3][5] naturally follows the chain of pointers and gives you what
>> you want; it also forces your last index to change most rapidly as you
>> walk through memory. So it would be very odd if multidimensional
>> arrays defined without pointers but using the same syntax were indexed
>> the other way around. (Let's ignore abominations like 5[3[2[a]]].)
> Hey, maybe it is only speculation, but this is the most convincing argument
> for breaking Fortran convention that I've ever heard

I think that arrays are just syntax on pointer is indeed the key
reason for how C works here. Since a[b] really means a + b (which is
why 5[a] and a[5] are the same), I don't see how to do it differently.

> (although I'm not sure if
> C was really breaking Fortran convention, as both languages should have born
> more or less in time, although I'd say that Fortran is a bit older).

Fortran is the oldest language I am aware of - certainly the oldest
still widely in use. it is even older than Lisp, the first version is
from 1956-57, and was proposed by Backus to IBM in 53 according to
wikipedia. It was created at a time where many people thought the very
idea of a compiler did not make any sense and was impossible. So yes,
Fortran is *much* older than C.



More information about the NumPy-Discussion mailing list