Richard Maine wrote:
> David Wong writes:
>
> > Here is a simple example in which I declare an array, DATA(-1:3).
> > When I pass
> > it to a subroutine, the indexes are changed to 1 to 5. Is this a bug in
> > the compiler or in the language specification?
>
>
>
> The compiler won't pass the bounds for you (except in the pointer
> case). If you want the lower bound passed, you have to do that
> yourself. Something like
>
David, you may also want to sit back and think about why you need a negative subscript. In my
experience, they are not worth the bother. F77 programmers would sometimes use the (:0)
subscripts to encode info that F77 didn't support, but you don't give us much background to
determine if you have f77 issues to contend with. If you do, maybe there is another way of
doing what you want.
The reason F90 acts this way (I guess) is that when you pass a section of an array into a
routine, you don't want to be hobbled by the fact that the section was (12:43,22:23). You want
to treat the section as an array in its own right. The fact that you need the original,
possibly oddball bounds might be a warning not to use a subroutine at all; and if you really
do, passing the bounds in will be a good self documenting step to the reader, warning him/her
that "The original bounds actually matter this time!"
Alvaro Fernandez
Rice University
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|