From: A Watcher on
At work we have a large legacy application with thousands of lines of
code and hundreds of subroutines. I've worked on it for years and now
they've assigned a jr programmer to do maintenance work as I've already
retired twice. The new person has a computer science degree but has
never seen fortran before.

She introduced a coding error that I had a real hard time tracing down.
She set x=0 where x was an allocatable array that hadn't been
allocated yet. What happened was some other data got set to zero, but
the program didn't blow up until the zero data caused problems.

Should that have been caught at run time? I have turned on all of the
runtime error checking that I could find. The program runs on an
elderly RS6000 AIX system and uses the IBM xlf compiler.
From: glen herrmannsfeldt on
A Watcher <stocksami(a)earthlink.net> wrote:
(snip)

> She introduced a coding error that I had a real hard time tracing down.
> She set x=0 where x was an allocatable array that hadn't been
> allocated yet. What happened was some other data got set to zero, but
> the program didn't blow up until the zero data caused problems.

> Should that have been caught at run time?

No. While ALLOCATABLE isn't quite like pointers, the effect
in this case isn't so different.

> I have turned on all of the
> runtime error checking that I could find. The program runs on an
> elderly RS6000 AIX system and uses the IBM xlf compiler.

Also, as with other variables that haven't been initialized,
the bounds, which might be checked with bounds checking haven't
been set. If you have undefined value checking, as in another
thread, it might detect it, but that is rare.

-- glen
From: dpb on
A Watcher wrote:
> At work we have a large legacy application with thousands of lines of
> code and hundreds of subroutines. I've worked on it for years and now
> they've assigned a jr programmer to do maintenance work as I've already
> retired twice. The new person has a computer science degree but has
> never seen fortran before.
>
> She introduced a coding error that I had a real hard time tracing down.
> She set x=0 where x was an allocatable array that hadn't been allocated
> yet. What happened was some other data got set to zero, but the program
> didn't blow up until the zero data caused problems.
>
> Should that have been caught at run time? I have turned on all of the
> runtime error checking that I could find. The program runs on an
> elderly RS6000 AIX system and uses the IBM xlf compiler.

It is (of course, and as I'm sure you know and isn't the question)
illegal to refer to the array until and unless it has been allocated.
But, afaik, it's not required to be diagnosed.

--
From: Craig Powers on
A Watcher wrote:
> At work we have a large legacy application with thousands of lines of
> code and hundreds of subroutines. I've worked on it for years and now
> they've assigned a jr programmer to do maintenance work as I've already
> retired twice. The new person has a computer science degree but has
> never seen fortran before.
>
> She introduced a coding error that I had a real hard time tracing down.
> She set x=0 where x was an allocatable array that hadn't been allocated
> yet. What happened was some other data got set to zero, but the program
> didn't blow up until the zero data caused problems.
>
> Should that have been caught at run time? I have turned on all of the
> runtime error checking that I could find. The program runs on an
> elderly RS6000 AIX system and uses the IBM xlf compiler.

It depends what you mean by "should".

From my point of view, quality run-time bounds-checking would also pick
an error like this up, but it does seem like something that is very much
a QoI issue.
From: steve on
On Jun 16, 7:50 pm, dpb <n...(a)non.net> wrote:
> A Watcher wrote:
> > At work we have a large legacy application with thousands of lines of
> > code and hundreds of subroutines.   I've worked on it for years and now
> > they've assigned a jr programmer to do maintenance work as I've already
> > retired twice.  The new person has a computer science degree but has
> > never seen fortran before.
>
> > She introduced a coding error that I had a real hard time tracing down.
> >  She set x=0 where x was an allocatable array that hadn't been allocated
> > yet.  What happened was some other data got set to zero, but the program
> > didn't blow up until the zero data caused problems.
>
> > Should that have been caught at run time?  I have turned on all of the
> > runtime error checking that I could find.  The program runs on an
> > elderly RS6000 AIX system and uses the IBM xlf compiler.
>
> It is (of course, and as I'm sure you know and isn't the question)
> illegal to refer to the array until and unless it has been allocated.
> But, afaik, it's not required to be diagnosed.

xlf is a F2003 compiler. Does 7.4.1.3 apply?

If variable is an allocated allocatable variable, it is
deallocated if expr is an array of different shape or any
of the corresponding length type parameter values of
variable and expr differ. If variable is or becomes an
unallocated allocatable variable, then it is allocated with
each deferred type parameter equal to the corresponding type
parameters of expr, with the shape of expr, and with each
lower bound equal to the corresponding element of LBOUND(expr).

In other words, allocate on assignment.

--
steve