gnu_fortran / 13 / behavior-on-integer-overflow.html

4.11 Behavior on integer overflow

Integer overflow is prohibited by the Fortran standard. The behavior of gfortran on integer overflow is undefined by default. Traditional code, like linear congruential pseudo-random number generators in old programs that rely on specific, non-standard behavior may generate unexpected results. The -fsanitize=undefined option can be used to detect such code at runtime.

It is recommended to use the intrinsic subroutine RANDOM_NUMBER for random number generators or, if the old behavior is desired, to use the -fwrapv option. Note that this option can impact performance.

© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gfortran/Behavior-on-integer-overflow.html