On Saturday, September 3, 2016 at 11:02:43 AM UTC-7, Gordon Sande wrote:
(snip)
> The classical Fortran error is an out of range subscript which allows
> you to store into parts of the executable code. The symptoms are often
> remote from the error.
In all the years I have been writing programs, and known that this could
happen, I don't know of any actual case. In the Fortran 66 days, code and
data were usually close together. That is much more rare now.
> The same effect can also be achieved by having an argument
> mismatch, like array being given a scalar, in a call. If you are lucky
> and the subscript is wild enough you get then you get a memory fault.
A common implementation of malloc() in C stores the actual length
just before the part that you use. Storing just before the beginning, or
just after (and so just before the next one) tends to really mess up the
allocation system. As many Fortran libraries now use the C library to
do things like allocation, this still applies here.
> For that you need an unintialized subscript. or floating point or such.
> The more usual running of the end of an array just
> gets modified code, like the buffer overflow errors that trouble lots of code.
When you start mixing up integers and pointers (easier in C, but not so
hard here) things can go bad fast.
One that I still remember watching people do so many years ago, when
I knew many beginning Fortran programmers, was to forget (or not know
about the need to) dimension arrays in subroutines. The result is that the
compiler assumes it is a function being passed as an actual argument, and
then starts executing your data. No compile time message about this.
It was common enough that one could guess the problem before knowing
anything else about the program.
(With static allocation Fortran 66, some of the other allocation based
problems didn't occur.)