Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

silent integer overflow

eliosh
Beginner
461 Views
The following example is taken from Nick MacLaren's slides (Cambridge Univ.)

[plain]program intoverflow
integer, parameter :: n=1800
integer :: n3

! real :: my_data(n*n*n) <---- Ooops here

n3 = n*n*n
print *, 'n^3 =', n3

end program intoverflow[/plain]
When compiled by ifort (v11.1.046) the overflow is not signaled and n3 becomes equal to 1537032704 instead of 5832000000.
gfortran, on the other hand, does recongize the problem and emits an error message during compilation.
0 Kudos
1 Reply
Ron_Green
Moderator
461 Views
Quoting - eliosh
The following example is taken from Nick MacLaren's slides (Cambridge Univ.)

[plain]program intoverflow
integer, parameter :: n=1800
integer :: n3

! real :: my_data(n*n*n) <---- Ooops here

n3 = n*n*n
print *, 'n^3 =', n3

end program intoverflow[/plain]
When compiled by ifort (v11.1.046) the overflow is not signaled and n3 becomes equal to 1537032704 instead of 5832000000.
gfortran, on the other hand, does recongize the problem and emits an error message during compilation.

This question comes up from time to time. There is a feature request to enable a compile time check for just such a situation. However, there is no requirement in the Fortran standard to emit an error for this scenario. This feature request is currently on our list but there is no timeline for it's implementation.

0 Kudos
Reply