Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Integer*4 Range Warning

gryvon
Beginner
392 Views

The code below results in "0 error(s), 0 warning(s)"

program test
implicit none
integer*4, parameter :: p = -2147483648
write(*, *) p
stop
end program test

and produces correct screen output ofthe left border of32-bit (signed, two's complement) integer value range-2,147,483,648 through 2,147,483,647

BUT the following code

program test
implicit none
integer*4, parameter :: p = -2147483648_4
write(*, *) p
stop
end program test

results in "Warning: The INTEGER(KIND=4) value is out-of-range. [2147483648]"

The screen output is still correct.

Please comment on this compiler behavior.

Thank you.

0 Kudos
1 Reply
TimP
Honored Contributor III
392 Views
You may think this is somewhat pedantic, but the value you supply is interpreted as a positive number, before it is negated. A common circumlocation would be (-2147483647_4 - 1_4). This avoids the trouble with the range of the number system.
0 Kudos
Reply