[MPI3 Fortran] Results of San Jose Forum meeting

N.M. Maclaren nmm1 at cam.ac.uk
Thu Mar 11 11:14:47 CST 2010


On Mar 11 2010, Bill Long wrote:
>
>I think this is only ensured if the type is a bind(c) type.  If you use
>
>type,bind(c) :: MPI_Comm
>     integer(c_int) :: val
>end type MPI_Comm
>
>which corresponds to a C structure with one member of type int. The C 
>standard requires that "A pointer to a structure object, suitable 
>converted, points to its initial member ...".  Unnamed padding at the 
>beginning of a C struct is prohibited.  And Fortran is required to 
>follow the C rules for layout of a bind(c) type. So, if something like 
>this is passed by address, then the address of the struct and the 
>address of the integer will be the same, and you get your "same memory 
>layout" requirement satisfied.  You also have something that can be 
>legally passed to a C routine.

Yes and no.  Firstly, it is important to note that it is only true if
a pointer to the object is passed - those can be (and often are) of
different lengths.  Secondly, casting a pointer to an integer to a
pointer to such a structure may be illegal (alignment).  So, while that
can be made to work, it's not easy to walk through the minefield.

Regards,
Nick Maclaren.





More information about the mpiwg-fortran mailing list