I'm not sure if you might need this, or maybe someone else, so here is a workaround.
For reproducing the problem, print *, -2147483648
yields 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:
Default kind of integer in Fortran is type 4, which is of type signed-int32. Because there is no symmetric equivalent to -2^[n-1] on the positive side, gfortran interprets this value as it evaluates the numerical part first before the sign part (coming to +2^[n-1]).
Other compilers could be following another convention, such as going with the sign first and then with the magnitude
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?