Hi there William, Why exactly is this not standard conforming? In the main program unit he's calling Huge(x) where x is of type integer(4) and storing it in an element of array b (also of integer(4)); and this is being passed to dummy array "array" in the subroutine (yet again of integer(4)). When I print (or use gdb) to view the contents of this variable it appears on my machine to indeed be 2^n(machine dependent, I assume)-1. Is there some bizzare quirk about the Huge() routine that I am missing? I would have checked the definition in my copy of Modern Fortran Explained or in the Standard but I am not at my work desk right now. Cheers, Adam Hirst P.S. I was just about to send a message saying that by my reckoning, the program should have indeed terminated with a result of 12 (with the addition that the Function should of course have been defined as a Subroutine, I guess that was just a typo.) On 27/06/16 19:45, William Clodius wrote: > The code with huge as array(2) is not standard conforming and gfortran can any of: > 1. Not attempt to deal with the resulting overflow and generate the efficient code with the likely infinite runtime; > 2. Insert a test for the overflow and generate a runtime error; > 3. Insert a test for the overflow and kluge around the overflow as a special case giving the expected result; and > 4. Treat i as integer(8) and not generate an overflow in spite of the type declaration. > > There may of course be other options. I suspect ifort by default does 1 with the compiler switches used, while gfortran does 3 unless debugging switches are set, and does 2 with some combination of compiler debugging switches. > >> On Jun 27, 2016, at 6:56 PM, Jan Hubicka wrote: >> >> Hello, >> I have a Fortran question. The following program loops infinitly when compiled >> with ifort -O0, while it does the expected number of iterations with gfortran. >> The issue is that we do produce quite ineffective code to deal with >> side cases like this. >> >> is the program bellow valid and expected to terminate? If so I guess we want >> to have it as a testcase. >> >> Thanks, >> Honza >> >> program test_program >> integer(4) :: b(2), a(22), x >> integer(8) :: suma >> >> b(1) = huge(x)-10 >> b(2) = huge(x) >> >> call test2(b, suma) >> print *,suma >> >> end program test_program >> function test2(array, s) >> integer(4) :: i, block(9), array(2) >> integer (8) :: s >> s = 1 >> >> do i = array(1), array(2) >> s = s + 1 >> end do >> >> end function test2 >> > -- Using GPG? Add my key, and respond to me with it enabled! Also, feel free to verify my key with me online or in person! Not using GPG? You should, it's easy! https://www.enigmail.net/documentation/quickstart.php