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



On 2007-03-30, Beliavsky <beliavsky@xxxxxxx> wrote:
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 .

NAGWare Fortran 95 compiler Release 5.1(282) on Intel Linux and with
the -C=all option gives the following error at runtime:

Rank 1 of IVEC(1:I) has extent 3 instead of 2
Program terminated by fatal error
Aborted

Kind regards,
Bart

--
"Share what you know. Learn what you don't."
.



Relevant Pages

  • Re: array operations on non-conforming arrays -- do compilers catch them?
    ... many invalid uses of non-conforming arrays when array subscripts ... For the following invalid code, ... Array bound mismatch, ... I discovered such a bug in my production code using the new Gfortran ...
    (comp.lang.fortran)
  • Re: Who uses clapack?
    ... > functions like SUM and MAXVAL and the ability to use array sections ... > drastically change the meaning of a Fortran code. ... >>Have you ever seen those bills for a Fortran compiler for an ... engineering applications in the C and C++ languages. ...
    (comp.lang.fortran)
  • Re: Who uses clapack?
    ... > functions like SUM and MAXVAL and the ability to use array sections ... > drastically change the meaning of a Fortran code. ... >>Have you ever seen those bills for a Fortran compiler for an ... engineering applications in the C and C++ languages. ...
    (sci.math.num-analysis)
  • Re: Benchmarking APL
    ... with that of FORTRAN. ... APL a 400% gain in programming efficiency could be obtained with only ... Another good-for-APL array problem, vector convolution, gave these ... Tomcatv, one of the SPEC benchmarks, is more typical of large array ...
    (comp.lang.apl)
  • Re: Mixing C++/Fortran using Two-Dimensional Array
    ... not a subset as in Fortran. ... if you really need it you can get the effect by an array of TYPE ... the lowest-level base element pointer, which is all you actually need ... macros in C, although it can be difficult to find macro names that are ...
    (comp.lang.fortran)