Reputation: 937
I am setting an integer to a value less than its maximum, but receiving an error that it is too big for it's kind. Why is this? Here is a sample program.
program max_int
integer, parameter :: i32 = selected_int_kind(32)
integer(kind = i32) :: my_int
!The largest integer of this kind
print*, huge(my_int)
!This works
my_int = 100000
!This doesn't, and gives an error.
!my_int = 1000000000000
print*, my_int
end program
Upvotes: 2
Views: 3584
Reputation: 858
You need to append the i32
to 1000000000000
like this: 1000000000000_i32
. gfortran complains that the number is too big for it's kind. 1000000000000
is a short integer, not a super long integer. 1000000000000_i32
is a super long integer. It is not complaining about the variable, it's complaining about the constant.
Upvotes: 7