Compilation warning with gfortran on assignment of LOGICAL(C_BOOL) variable

Viewed 248

I am using a program that uses mixed language C and Fortran, like in the following example.

PROGRAM boolean
   USE ISO_C_BINDING
   IMPLICIT NONE
   LOGICAL (KIND = C_BOOL) :: cbool
   INTEGER :: i, j
   i = 1
   j = 2
   cbool = i /= j
   WRITE(*,*) cbool
END PROGRAM boolean

I compile it on Windows 10 with gfortran 10 from MSYS2-MINGW64 distribution using the following command:

gfortran boolean.f90 -o boolean -Wall

And I get the following warning message:

boolean.f90:8:11:

    8 |    cbool = i /= j
      |           1
Warning: Possible change of value in conversion from LOGICAL(4) to LOGICAL(1) at (1) [-Wconversion]

I can solve this warning by changing to:

 cbool = LOGICAL(i /= j,1)

I understand that this is because a different storage size is used by C_BOOL and the default logical in gfortran.

The questions: under what circumstances is it possible for the value to change as the warning says? What is the best way to remove this warning message, appart from using the LOGICAL intrinsic function?

0 Answers
Related