79609123

Date: 2025-05-06 16:41:29
Score: 1.5
Natty:
Report link

I'm not sure if you might need this, or maybe someone else, so here is a workaround.

For reproducing the problem, print *, -2147483648yields the following on my machine:

Error: Integer too big for its kind at (1). This check can be disabled with the option ‘-fno-range-check’

Now, the default type of integer in Fortran is type 4, hence the early comment by @jhole.

We can however, make it compliant with print *, -2147483647 - 1, which will output the expected -2147483648.

OR

You can also specify a bigger int for the type of output:

program bigint
integer, parameter :: int64 = selected_int_kind(18)
print *, -2147483648_int64
end program bigint

output would be -2147483648

To answer your questions specifically:

Am trying to find a cite for you here: https://gcc.gnu.org/onlinedocs/gfortran/, I hope I will be successful

Here's a very similar post for you in the meantime. The logic still stands: Why Negating An Integer In Two's Complement and Signed Magnitude Can Result In An Overflow?

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • User mentioned (1): @jhole
  • Looks like a comment (1):
  • High reputation (-1):
Posted by: Tino D