Python/Fortran interoperability

James Van Buskirk not_valid at comcast.net
Mon Aug 24 22:55:19 CEST 2009


"Richard Maine" <nospam at see.signature> wrote in message 
news:1j4y84p.v5docbtueccmN%nospam at see.signature...

> There might be a confusion here (and I'm not even sure on whose part) on
> a picky but important detail of wording. I have seen multiple people
> confused by this one before. In fact, some potential confusion was
> forseen, which is why there are notes specifically about it in the
> Fortran standard (see below). Those notes do tend to get overlooked
> though.

> 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.

> See Note 15.19 (which in turn cites an example in Note 15.23) of f2003.
> You can pass a Fortran string of length n as an actual argument
> corrseponding to a dummy argument that is an array of n character*1
> elements. This isn't considered a question of "interoperability", as it
> is a feature purely within Fortran, but it does impact on what kinds of
> things work.

> One might plausibly regard this as a kludge, but it is a kludge that is
> part of the Fortran standard and is guaranteed to work with all Fortran
> compilers. I almost said all f2003-compliant compilers (admittedly a
> limited set), but then I recalled that the feature actually dates back
> to f77 when character type was introduced; f2003 just extends it to the
> C character kind for the obscure case where the C character kind might
> be different from the default character kind (I don't know of any
> compilers where this is so, but the standard allows for it).

No, this is a tricky point.  It was allowed in f77 to pass an array
actual argument to a scalar character dummy argument, but the ability
to pass a scalar character actual argument to an array dummy argument
is new to the sequence association rules of f2003.  So your first
impression was more accurate than the result of thoughtful reflection :)

-- 
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end





More information about the Python-list mailing list