Didn't get expected runtime error for array bounds exceeded

Hi,

If compiled these codes without bound checking option,

with PGI, didn’t get an expected runtime error instead an incorrect result.

with Intel and Gfortran, got the runtime error as expected

program loop
 implicit none
 real, allocatable ::  u(:)
 integer i
 allocate(u(10))
 do i=1,11 ! off-by-one error
 u(i)= i * 1.0
 enddo
 print *,"i=",i, "u=",u(i)  <-----
 deallocate(u)
end

[jliu@fat ~]$ pgf90 loop.f90
[jliu@fat ~]$ ./a.out
 i=           12 u=    0.000000

If I didn’t make misunderstanding, it should get the expected runtime error whether if using bound checking option or not.

My question is

why PGI compiler failed to make the expected runtime error if without bound checking option ?

Thanks for any comments

Jerry

it should get the expected runtime error whether if using bound checking option or not.

No, your expectation is incorrect.

A Fortran program with an array bound overrun is, in the language used in the Fortran standards, a “non-conforming” program, and its run-time behavior is “undefined”.

This implies that you should have no expectations as to what the non-conforming program should do.

The program may not run at all, may run and give “correct” results, may cause mountains to start flying, turn all street lamps on at noon,…: all these events come under “undefined”.

NS99,

Got it.

Thank you very much for the great explanation.

Regards

Jerry

You must use allocate(u(11))

Your print must be inside the do-loop

The program runs successfully with these statements and gives u=1.000000
and doesn’t need to generate the next value of i where u undefined.

You must use allocate(u(11))

Your print must be inside the do-loop

The program runs successfully with these statements and gives u=1.000000
and doesn’t need to generate the next value of i where u undefined.