array operations on non-conforming arrays -- do compilers catch them?



I am finding that most Fortran 95 compilers do not catch, even at run
time, many invalid uses of non-conforming arrays when array subscripts
are variables. For the following invalid code,

program xsum_nonconform
integer, parameter :: n = 3
integer :: i,ivec(n)
ivec = 1
do i=n,n
print*,ivec(1:n-1) + ivec(1:i)
end do
end program xsum_nonconform

G95, Intel Visual Fortran, and Salford don't detect a problem at
compile or run time, but gfortran -fbounds-check says

Fortran runtime error: Array bound mismatch, size mismatch for
dimension 1 of array 'ivec' (in file 'xsum_nonconform.f90', at line 6)

and Lahey/Fujitsu with -chk says something similar.

I discovered such a bug in my production code using the new Gfortran
windows binary, dated 2007-03-29 .

.



Relevant Pages

  • Re: Passing C structures as arguments
    ... > wondering if it is possible to pass in these arguments from a Fortran ... depending on the particular compilers. ... Be aware that Fortran pointers are *NOT* the same thing as ... You may need to play compiler-specific games for the array case, ...
    (comp.lang.fortran)
  • Re: How to construct a heterogenous list?
    ... Does anyone know how, in Fortran, to construct a linked list, the ... If you think to involve pointers to the different types, ... allocate an array to hold the result. ... I might add that compilers don't tend to do well with it. ...
    (comp.lang.fortran)
  • Re: Ada.Containers.Vectors - querying multiple elements
    ... there would be a distributed overhead. ... compilers store it separately. ... In order to be able to represent an array as ... so I don't think it would make sense to allow 'First to be an invalid ...
    (comp.lang.ada)
  • Re: Namelist correctness question
    ... Although namelist was not standardized until f90, it was supported by most vendors and most compilers before that. ... array and read data into subsequent elements. ... at least as far as I can tell from the GC28-6515-10, the May 1974 edition of the IBM OS/360 Fortran manual. ... the May 1993 manuals for VS Fortran. ...
    (comp.lang.fortran)
  • Re: null terminated strings
    ... descriptor, but the address of the first element of the array, and the array size needs to be defined in the subprogram? ... This meets all the behaviours required by the Fortran standard. ... are F90, and later, F95 standard compilers. ...
    (comp.os.vms)