Re: INTERFACE problem

From: Richard E Maine (nospam_at_see.signature)
Date: 03/28/05


Date: Mon, 28 Mar 2005 08:23:19 -0800


[P.S. No, I do not answer Fortran questions like this in private email.
I provide my email address for matters that might be personal or private
- not as a place to obtain private consulting. I can justify spending
NASA-paid time answering questions in a public forum. That counts as
educational outreach and also as adequately related to my work on the
standard. There is no way I can adequately justify why NASA would be
paying me while I do private personal consulting.

Besides which, I'd be a spectacularly poor person to get private
consulting from on this, since it is clearly about compilers that I
don't use and things I haven't done. Keep followups to the newsgroup,
please.]

I wrote:

> > C pointers and Fortran pointers are not
> > the same thing. Since you don't show anything about the function, I
> > can't tell what it does look like, but the odds that it returns a
> > Fortran-compatible pointer don't seem good. Any such thing is certainly
> > very vendor-specific...

In article <d9a353ac.0503262349.3fba87b9@posting.google.com>,
 dvorkin@omsu.ru (Pavel) wrote:

[gave details about the C function]

> Now I want to call this function from Fortran and be able to get
> access to the fields.

I suppose that I indirectly asked for this by mentioning that you hadn't
shown details of the function. You do here show some details. However,
note that I also said "Any such thing is certainly vendor specific". I
intended that as a recommendation against doing this.

Your odds might be improved by the fact that it is a scalar. Hmm, but
there are nonscalar pointers in the structure, so I guess that kicks you
out of the simple case. In any case, it is vendor-specific and I still
recommend against it. I recommend keeping the allocation in Fortran. If
you choose not to follow that recommendation, then you'll have to get
help elsewhere because I follow my own advice in this case (and thus
have little experience from which to help you). Also, if you mentioned
the vendors involved, I overlooked it (though I can make some guesses
based on a nonstandard feature in the code); if you are looking for a
vendor-specific answer, it helps to know the vendors.

F2003 provides facilities for doing things like this portably, but I
don't know what compilers might implement those facilities yet. It
certainly doesn't yet count as portable, even if a few compilers do it.
I could probably come up with an example of the f2003 code for this (but
I can't test it because I don't have a copy of any compiler that
implements it - though I've heard such things exist). If someone would
like me to take a shot at that, I'll try (in a separate posting because
I want to move on to something else right now - and only if asked), but
I repeat - it won't help solve a problem today.

As an aside, I also recommend against functions that return pointers,
even without the complication of C-Fortran interop. I recommend using
subroutines instead. In fact, I consider that a strong enough
recommendation that I decline to help people do functions that return
pointers. If they need my help to do such functions in the first place,
then they are almost guaranteed to get into trouble trying to use them.

> I do now
...

> FUNCTION F1N [C, ALIAS:'_InitMyType'] ()

This isn't Fortran. It is a vendor extension. It is also a vendor
extension that I have zero experience with and thus would be of little
help with.

-- 
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain


Relevant Pages

  • Re: bad debts among Generation Y
    ... Since I recommend against academic science, in general, and recommend ... told me that he prefereed to work in the private organisations as ... inefficiency and backstabbing etc in the government organisations. ...
    (sci.research.careers)
  • Re: bad debts among Generation Y
    ... Since I recommend against academic science, in general, and recommend ... told me that he prefereed to work in the private organisations as ... inefficiency and backstabbing etc in the government organisations. ...
    (sci.research.careers)
  • Re: another unknown online vendor
    ... SIGH So you'd recommend svp as a good online computer vendor. ...
    (uk.comp.vendors)
  • Re: W2K
    ... You need to know how to run and maintain (and not screw up) a Domain before ... I recommend *not* naming your new domain the same as whatever your company ... outside world you might be known by "mycompany.com" while in the private ... > Small office trying to achieve placing user profiles on> one server running W2K. ...
    (microsoft.public.win2000.networking)
  • Re: Windows XP Home Logon to NT 4.0 Domain
    ... If that vendor is saying they do not recommend XP Pro ... > Bought some Compaq Presarios with factory installed XP ...
    (microsoft.public.windowsxp.security_admin)