Python/Fortran interoperability

nmm1 at cam.ac.uk nmm1 at cam.ac.uk
Mon Aug 24 14:55:38 EDT 2009


In article <1j4y84p.v5docbtueccmN%nospam at see.signature>,
Richard Maine <nospam at see.signature> wrote:
>
>Only character strings of length 1 are interoperable, as the term
>"interoperable" is defined in the Fortran standard. However, that does
>not mean that only character strings of length 1 will work with C. The
>distinction might be picky, but it is important.

Precisely.  And the kludge does NOT work under all circumstances,
which is why I said that it doesn't work very well.

Consider, for example:

    SUBROUTINE Fred (X) BIND(C)
    CHARACTER*(*) :: X
    END SUBROUTINE Fred

    CHARACTER(LEN=100) :: string
    CALL Fred(string(40:60))
    CALL Fred(string(5:50))

This is not currently allowed and raises all sorts of 'interesting'
implementation and portability questions.  For example, I defy anyone
to write Fred portably in C :-)

It gets really hairy if you have functions that have assumed length
results, but those are obsolescent.

Even when Fred has an explicit length, there are some problematic
cases, which could catch out programmers in one language that don't
know the other fairly well.  But those are much less of a problem
than the common need for assumed length CHARACTER arguments.


Regards,
Nick Maclaren.



More information about the Python-list mailing list