[J3] C_PTR not allowed in SEQUENCE types?
Malcolm Cohen
malcolm at nag-j.co.jp
Fri Mar 12 02:41:40 UTC 2021
If it’s written by a C program, definitely.
If it was written by another Fortran program compiled by another Fortran compiler, BIND(C) is good if all the components are interoperable. SEQUENCE may work otherwise...
Of course, different compilers may have differing alignment rules; yes, even on the same hardware, and even if they are both C compilers or both Fortran compilers. So if the derived type has a mixture of sizes and alignments, there may be nothing that would work short of reading all the bits into an integer array and extracting them manually. Ugh. Fortunately that doesn’t happen very often, but it does happen.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Van Snyder via J3
Sent: Friday, March 12, 2021 11:12 AM
To: j3 at mailman.j3-fortran.org
Cc: Van Snyder <van.snyder at sbcglobal.net>
Subject: Re: [J3] C_PTR not allowed in SEQUENCE types?
Many years ago, I inherited a program that used a SEQUENCE type to read data from a direct-access file that had been written by another program, probably a C program.
I assume that if anybody wants to fiddle that code again, the SEQUENCE type ought to be a BIND(C) type, right?
On Fri, 2021-03-12 at 09:10 +0900, Malcolm Cohen via J3 wrote:
Yes, BIND(C) is necessary for interfacing to C (and thus to other languages that use C-like interfaces). And MPI is at root a C library so one would expect them to be making heavy use of BIND(C).
So my question would be why is MPI using SEQUENCE and not using BIND(C)?
Perhaps they want derived types in mpif.h? And therefore need SEQUENCE to make them the same derived type in every place that INCLUDEs it?
That’s not really a memory layout question (if you want to have the same memory layout as C, well that is what BIND(C) is for). But a question of an “old fashioned programming style” viz not using those new-fangled modules that have only been around for thirty years (more than ten years longer than C_PTR).
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org <mailto:j3-bounces at mailman.j3-fortran.org> > On Behalf Of Bader, Reinhold via J3
Sent: Friday, March 12, 2021 12:02 AM
To: General J3 interest list <j3 at mailman.j3-fortran.org <mailto:j3 at mailman.j3-fortran.org> >
Cc: Bader, Reinhold <Reinhold.Bader at lrz.de <mailto:Reinhold.Bader at lrz.de> >
Subject: Re: [J3] C_PTR not allowed in SEQUENCE types?
Hi Bill,
> On a related issue, I'm not really sure why SEQUENCE is not already in the list of Obsolescent features.
I had a discussion on this recently with Rolf Rabenseifner (from the MPI Forum). Sequence types feature prominently in the
type API of MPI for the Fortran interface, because the memory layout is not sufficiently specified for non-SEQUENCE / non-BIND(C) types.
I would assume quite some MPI codes use this, and it would be a significant imposition if SEQUENCE were on the way to be
removed.
Cheers
Reinhold
Disclaimer
The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. Please see our Privacy Notice <https://www.nag.co.uk/content/privacy-notice> for information on how we process personal data and for details of how to stop or limit communications from us.
This e-mail has been scanned for all viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210312/afe61cbb/attachment-0001.htm>
More information about the J3
mailing list