简体   繁体   中英

iand with different kind parameters using new gfortran version

I am currently working with old code, that calls the iand function with integers of different kinds as arguments. Here's a small example of what the code includes:

program test
    integer*1 i
    integer j, k 

    i = 1
    j = 8 

    k = iand(i, j)
    print *, k
end program test

gfortran versions 8 and earlier had as an extension the ability to call iand with integers of different kind (see, for instance, here ), whereas this option was removed in gfortran 9 (see this site ). For instance, with gfortran 7.5.0:

gfortran-7 -o test test.f90 && ./test
       0

But when compiling with gfortran 9.2.0, I get:

gfortran -o test test.f90
...
Error: Arguments of ‘iand’ have different kind type parameters at (1)

Is there an option for the new version of gfortran to let me use this code as is?

No, there isn't. This extension was removed as the semantics weren't well specified, and fixing the code to be standard conforming is simple.

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81509

In your case, something like

k = iand(int(i, kind(j)), j)

is hopefully what you're after.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM