Python/Fortran interoperability

sturlamolden sturlamolden at yahoo.no
Mon Aug 24 13:23:55 EDT 2009


On 24 Aug, 18:20, n... at cam.ac.uk wrote:
>This obviosuly proves you wrong:
>
> Er, no, it doesn't.  I suggest that you read what I said more
> carefully - and the Fortran standard.  As I said, you can kludge
> them up, and that is precisely one such kludge -

You said we have to kludge them up as arrays. I did not. I kludged up
the C string as a pointer to a Fortran string, and called strlen to
get the length of the C string. You also said we can only interop with
length-1 character strings. My kludge was valid Fortran and works with
strings of any length up to some sane limit that you can specify.

You cannot expect a C pointer to carry information about the length of
the string. C strings are nul terminated, which is precisely why we
have strlen. When C has to use strlen to get the length of a C string,
so does Fortran. You cannot use the Fortran standard to change the
behaviour of C.


> but, as I also
> said, it doesn't work very well.

Only if you have an incredibly stupid compiler.


Sturla



More information about the Python-list mailing list