How to rewrite iand to conform with newer versions of gfortran

I am working with an older Fortran code and during compilation I get many different error messages, some of the of the following format:

if(iand(n_jz2_max,1).eq.0) then
Error: Arguments of ‘iand’ have different kind type parameters at (1)

where n_jz2_max is an integer*4.

I understand that the iand no longer supports parameters of different kind type, but I do not know how to change the code to be able to compile.

I tried to compile the code with an older version of gfortran, but this is not an option for me. The Ubuntu version I have installed does not allow me to install older versions of gfortran. Another solution would be to install an older Ubuntu version, but I prefer to make a try and change the code.


Thank you everyone for your answers. Indeed I was using compiler options like -fdefault-integer-8 which led to errors. This is how I was compiling the code: (The include option was added because the code depended on a file located inside a folder named "include".)

$ mpif90 -f90=gfortran -c -w -I include -O2 -fdefault-integer-8 -o build/mm_1.16.o source/mm_1.16.f90

After many unsuccessful tries, I ended up removing all mpich versions from my laptop and installing the newest version. I changed the compilation options to

$ mpif90 -c -w -I include -O2 -o build/mm_1.16.o source/mm_1.16.f90

and the code compiled without any issues.


  • As the comments mention, this shouldn't happen with the default compilation options. You're likely using -fdefault-integer-8 or something like that.

    What you can do to make sure that the kind of the literal 1 and the 0 matches the kind of n_jz2_max could be something like

    integer, parameter :: q = kind(n_jz2_max)
    if(iand(n_jz2_max, 1_q) .eq. 0_q) then