# Integer 4 or integer 8?

**URL:** <https://fortran-lang.discourse.group/t/integer-4-or-integer-8/3076>\
**Category:** Uncategorized\
**Created:** [March 30, 2022, 6:08pm UTC](https://fortran-lang.discourse.group/t/integer-4-or-integer-8/3076 "2022-03-30T18:08:12Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)\
**Post date:** [March 30, 2022, 6:54pm UTC](https://fortran-lang.discourse.group/t/integer-4-or-integer-8/3076/3 "2022-03-30T18:54:38Z")

</div>

In the original version of OP there was an array AAA(np,nd). I guess that internally, the processor should deal properly even with AAA(100000,100000) although the indices would overflow when simply multiplied.

In explicit calculations, however, one has to make sure there is no overflow and use proper kind(s). Note also, that with your declarations:

```auto
integer(kind=i4) :: np,nd
integer(kind=i8) :: jjj
jjj = np*nd

```

`jjj` will not be properly assigned if `np*nd` overflows in `i4` kind. Consider sample program:

```auto
program main
  use iso_fortran_env, only: i4=>int32, i8=>int64
  integer(i4) :: i=100000, j=100000
  integer(i8) :: bi,bj
  bi = i*j ! overflows, assigns bad value
  bj = int(i,kind=i8)*j ! converted to i8 before multiplication
  print *, bi, bj
end program main
! outputs: 1410065408 10000000000

```

---

_[View the full topic](https://fortran-lang.discourse.group/t/integer-4-or-integer-8/3076)._
