[Numpy-discussion] Fortran was dead ... [was Re: rewriting NumPy code in C or C++ or similar]

Sturla Molden sturla at molden.no
Tue Mar 15 13:55:09 EDT 2011


Den 15.03.2011 18:01, skrev Yung-Yu Chen:

> I really love the capabilities Fortran provides for quick array 
> operations, especially floating-points.  What I think Fortran is still 
> lacking is better support of C pointers and structures.

Fortran 90 has user defined types, but they are not ABI compatible with 
C structs. Fortran 2003 has ISO C bindings for this purpose.

There are usually proprietary extensions to Fortran for interfacing with 
C, it can be ways to declare C structs and pointers (e.g. Cray pointer). 
Relying on this is not protable though.

Another annoying part about Fortran is that it has four different ways 
of representing array dummy arguments: "explicit shape", "assumed-size", 
"assumed shape", and "deferred size". Usually one can assume that 
explicit shape and assumed-size arrays are passed as pointers to the 
first element, but the standard does not require this. For assumed shape 
and deferred size arrays, all bets are off, and we have to call this via 
a Fortran driver/proxy routine.

One would think that only one method would suffice, instead of four...

Not to mention that it e.g. is illegal to pass an array declared 
assumed-size to subroutines requesting an assumed-shape array. So they 
are not even compatible within the Fortran language.

Here they are, and observe that they cause different semantics and ABI:

Explicit shape:
integer :: m,n
real :: X(m,n)

Assumed size:
integer :: m
real :: X(m,*)

Assumed shape:
real :: X(:,:)

Deferred shape:
real, pointer :: X(:,:)
real, allocatable :: X(:,:)


Sturla






More information about the NumPy-Discussion mailing list