Re: Question about out-of-bounds warning



program main
integer :: i(2)
i (0:-1) = 1
end

Interesting: neither gfortran (GNU Fortran 95 (GCC) 4.3.0 20061223
(experimental)) nor Sun's f95 (f95: Sun Fortran 95 8.2 Patch 121020-04
2006/10/26) throw an error and both binaries run without any problems;

Yes, and they have a reason to do so. i(0:-1) = 1 is perfectly legal, and
does nothing at all: it takes all the elements in the section 0:-1 of the
i array, which means "no element", and sets them to 1.

one difference occurs when I try to print "i": the Sun binary just
print zeroes while the gfortran binary prints random integers.

Well, it depends on the compiler, the OS, the moon and your karma. You're
reading uninitialized memory.

--
FX
.



Relevant Pages