Re: [MPI3 Fortran] Fwd: [Mpi-comments] MPI 3.0: Fortran 2008 interface - issue with the LOGICAL kind
In C when any scalar value is converted to _Bool, the result is 0 if the value compares equal to 0; otherwise the result is 1. (6.3.1.3 Boolean type). The value of C_BOOL as a Fortran KIND type for LOGICAL is such that 1) The bitsize of LOGICAL(C_BOOL) matches the bitsize of _Bool in C for the companion processor. 2) The Fortran processor uses the internal bit pattern in LOGICAL (C_BOOL) of 0 to represent false, and 1 to represent true. If both of these is true (which is the case for many implementations) then C_BOOL > 0. Otherwise C_BOOL will be negative, and there is no interoperability with C for LOGICAL. The fatal flaw in the MPI interface here is that the corresponding C formal parameter is not _Bool or anything that looks like LOGICAL. Instead it is 'int'. There is no concept of a Fortran argument of type LOGICAL interoperating with a C formal parameter of type int. Usage of that sort in an MPI interface is simply wrong. One side or the other of the call needs to be fixed. I would vote for changing the Fortran side to be type INTEGER(C_INT). Cheers, Bill On 2/28/13 12:29 PM, Craig Rasmussen wrote:
Ack....
I just did a quick rereading of clause 15, Interoperability with C, and it appears ill defined to me. Consider the following:
1. Suppose a compiler has a default logical size equivalent to a default integer. Since the standard only requires one logical kind, this compiler may not have a type that is interoperable with a _Bool C type. In this instance C_BOOL would be a negative value. 2. If a compiler does support LOGICAL(kind=C_BOOL), what values of a C type _Bool map to .TRUE.? What values map to .FALSE.? These mappings may be in clause 15 but I didn't see them at first glance. 3. Suppose a Fortran compiler has the following mapping:
_Bool flag = 0; /* flag maps to .FALSE. */
if (flag != 0) ...; /* flag maps to .TRUE. */
This seems to me to be the sane way to map values from C to Fortran. The same mapping can be done for any C integer type to an equivalently sized Fortran LOGICAL.
-- Bill Long [email protected] Fortran Technical Support & voice: 651-605-9024 Bioinformatics Software Development fax: 651-605-9142 Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101
participants (1)
-
Bill Long