Re: Fortran/C string interop?
- From: Joe Krahn <lastname_at_niehs.nih.gov@xxxxx>
- Date: Mon, 08 May 2006 12:54:52 -0400
Richard E Maine wrote:
Joe Krahn <lastname_at_niehs.nih.gov@xxxxx> wrote:....
Yes, but C functions cannot normally handle Fortran arrays, without help from the proposed C array API.
I suppose it could be done manually by passing a C_PTR which points to the first character of a fixed string,
plus a length argument.
Yes. That's why I said "sure it does" above. Or for that matter, if it
is a sring whose length you always know independently, you don't need to
pass any length information at all.
I don't see what problem it is that you are proposing to solve. Until
there is a problem, I don't think we should be solving it. Passing a
string length separately is a perfectly "normal" thing to do in C for a
string without NUL termination. And it is simple to do in Fortran. Seems
to me that adding an API element for this is making things more
complicated instead of simpler. You sure wouldn't be able to call any
existing C code, which won't have the API calls, that way.
OK; I did not realize that some array information was inaccessible from Fortran. Maybe there should be some stride inquiry functions?
The situation with arrays is different. The difference does *NOT* have
anything to do with any percieved difference in importance of string
versus numeric data. The difference is that there are things that cannot
be done with some array cases without extra help from the standard. Note
the "cannot" there. This is not just a matter of syntactic sugar to
avoid having to pass shape information separately. In particular, you
cannot pass a noncontiguous array to C without copying it. And there
aren't even facilities to inquire about things like stride that would be
needed to access such arrays in C.
What about working with allocatable-length strings from C? Isn't that more like the array case? Alternatively, is the array API intended to be compatible with at least len=1 characters, so C can allocate an array of characters?
Seems to me that you are looking for the standard to come up with
something that a user could just as well do. For the array case, the
user can't do it. There are some areas where I recommend standardization
of things that users can do because those things are so widely needed or
because there is benefit to all users doing them the same way. But I
don't see either of those justifications as applying here. There is zero
existing code base that uses the as yet non-existant proposed API. A lot
of new C interoperating code will use NUL termination, as tends to be
common in C. In those remaining cases where it is necessary to pass a
string length, passing it as an explicit (manual, if you prefer)
separate argument doesn't seem like a big deal, is intuitive, and is
consistent with existing practice - heck, that even allows some existing
"normal" C functions to be used without change. I'm left seeing no
problem to be solved by standardizing a new API for this.
As for normal fixed-length Fortran strings, I suppose that passing a separate length argument is more consistent with C.
Joe
.
- Follow-Ups:
- Re: Fortran/C string interop?
- From: Richard E Maine
- Re: Fortran/C string interop?
- References:
- Fortran/C string interop?
- From: Joe Krahn
- Re: Fortran/C string interop?
- From: Richard Maine
- Re: Fortran/C string interop?
- From: Brooks Moses
- Re: Fortran/C string interop?
- From: Joe Krahn
- Re: Fortran/C string interop?
- From: Richard E Maine
- Fortran/C string interop?
- Prev by Date: Go To Statement Considered Harmful: A Retrospective
- Next by Date: Re: Go To Statement Considered Harmful: A Retrospective
- Previous by thread: Re: Fortran/C string interop?
- Next by thread: Re: Fortran/C string interop?
- Index(es):
Relevant Pages
|