Re: Fortran/C string interop?



Richard E Maine wrote:
Joe Krahn <lastname_at_niehs.nih.gov@xxxxx> wrote:
....

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.
Yes, but C functions cannot normally handle Fortran arrays, without help from the proposed C array API.


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.
OK; I did not realize that some array information was inaccessible from Fortran. Maybe there should be some stride inquiry functions?


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.

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?

As for normal fixed-length Fortran strings, I suppose that passing a separate length argument is more consistent with C.

Joe
.



Relevant Pages

  • Strange return values from Microsoft Fax API
    ... I'm using api function FaxConnectFaxServer and FaxEnumJobs from ... Microsoft FAX api with VB6 and getting a very strange array returned, ... MachineName As String, ByRef FaxHandle As Long) As Long ...
    (microsoft.public.win2000.fax)
  • Re: Looking for a better way to do this
    ... once it's in a standard byte array? ... like a possible way to go, or am I better off with the API function (if I ... ' Converts a portion of byte array to string. ... Call CopyMemory, ByVal lpByteArrayElement, nLen) ...
    (microsoft.public.vb.general.discussion)
  • Re: Looking for a better way to do this
    ... I thought VB6 stored in Little Endian, ... is there actually an API call to swap Endians? ... (And check into whether it can work directly on the Variant array or if I wanna pull it out into a byte array or whatever.) ... Private Function CVSAs String ...
    (microsoft.public.vb.general.discussion)
  • Re: OpenNETCF SetWirelessSettings
    ... If you use the byte array version of the ... should get the same thing as when you enter that string in the UI. ... corporate network via the ActiveSync connection. ... passing the string directly, and it worked. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Structure Marshalling Question
    ... > bones C API. ... > The BYTE array returned by this API function is actually text. ... > I would be perfectly happy to get this as a String, StringBuilder, ...
    (microsoft.public.dotnet.framework.interop)