On Mon, Mar 24, 2014 at 1:05 PM, Bill Long <[log in to unmask]> wrote:
>
> If there is no Fortran LOGICAL representation that matches the corresponding c _Bool then the value of c_bool in the iso_c_binding module should be -1. If that is what you find, then the compiler is behaving correctly.
The value of c_bool on Intel on my machine is "1", however, the type
is not interoperable, unless you specify -fpscomp logical. Btw, Cray
seems to have the same issue, see the results from a colleague who has
access to Cray: https://gist.github.com/jeffhammond/9746080
Ondrej
>
> Cheers,
> Bill
>
> On Mar 24, 2014, at 1:56 PM, Ondřej Čertík <[log in to unmask]> wrote:
>
>> Hi,
>>
>> The Fortran 2003 standard says that logical(c_bool) in Fortran and
>> "bool" in C should be interoperable. Unfortunately, this only works in
>> gfortran. Both Intel and PGI fail. Here is a minimal example:
>>
>> https://gist.github.com/certik/9744747
>>
>> PGI and Intel behave the same, and both fail. The reason is that Intel
>> represents .true. as -1, but when you pass true from C, it is
>> represented as 1. In Fortran, .not. causes 1 (= .true. in Intel
>> Fortran) to become -2 (still .false. in Intel Fortran), but when you
>> return to C, -2 is interpreted as true. I was using ifort and icc for
>> this example.
>>
>> Here are some relevant links if you want to learn more about this:
>>
>> http://gcc.gnu.org/onlinedocs/gfortran/Intrinsic-Types.html
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40539
>> http://software.intel.com/en-us/blogs/2012/05/11/doctor-fortran-in-i-can-c-clearly-now-part-i
>>
>> Intel has an option to fix this, it's enough to use -fpscomp logical,
>> though it might slow things down.
>>
>> Isn't this a bug in Intel? Because clearly, the logical(c_bool) and
>> bool are *not* interoperable in ifort (with default options), as my
>> example shows, using Intel's own Fortran and C compilers. I'll be
>> happy to report this as a bug, but I wanted to check with you first,
>> whether you agree that this is a bug.
>>
>> Ondrej
>
> Bill Long [log in to unmask]
> Fortran Technical Suport & voice: 651-605-9024
> Bioinformatics Software Development fax: 651-605-9142
> Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101
>
>
|