[MPI3 Fortran] [Mpi-comments] MPI 3.0: Fortran 2008 interface - issue with the LOGICAL kind
N.M. Maclaren
nmm1 at cam.ac.uk
Mon Mar 4 12:07:28 CST 2013
On Mar 4 2013, Craig Rasmussen wrote:
>>
>> B) There is no match between Fortran default LOGICAL and anything in
>> C. INTEGER(C_INT) has the right storage and wrong semantics;
>> LOGICAL(C_BOOL) has the right semantics and wrong storage.
>> LOGICAL(C_BOOL) is defined to interoperate with _Bool, but I wouldn't
>> trust it an inch. If it is never passed as VALUE, it will probably be
>> OK, but I wouldn't bet on it.
>>
>> Some C compilers will almost certainly quietly convert it to int in
>> arguments and results, with a kludge to make sizeof() and the unary '&'
>> operator work. Quite a lot have done (still do?) that with integers
>> shorter than int and reals shorter that double, to help with K&R
>> compatibility. If the Fortran compiler does the same, you are OK,
>> but I have seen nasty problems here.
>>
>> I don't see any practical option but to have non-BIND(C) wrappers.
>
> Nick, can't the wrapper C code safely cast to an integer (or simple
> assignment after testing for true/false) from a _Bool?
>
> To remove BIND(C) from the MPI-3 interfaces is practically very difficult
> to do because of the PMPI interaces.
I am not sure what you are proposing. My point is that LOGICAL almost
certainly will not be interoperable (i.e. is not available in BIND(C)
interfaces), and that using _Bool VALUE arguments or results is seriously
problematic, even when moving between two C compilers, let alone a C and
a Fortran one.
There isn't any difficulty about a Fortran wrapper using integers (as
C does), and converting them to LOGICAL, but it can't be BIND(C).
A wrapper written in C can't do anything useful, because there are no
interoperable LOGICAL types except the problematic LOGICAL(C_BOOL).
Regards,
Nick Maclaren.
More information about the mpiwg-fortran
mailing list