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?
Neither. Thats the way it is supposed to work. You are using an
assumed shape array as the dummy. That means just what it sounds like
- the shape is assumed. Shape is just the total size in each
dimension - it does not include the specific bounds. I'll not try to
explain why things are this way. See long previous discussions here
and/or on comp.lang.fortran.
> Using pointer can preserve the range of the index.
> However, I [have good reasons not to do that]
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
call sub(array, -1)
...
subroutine sub(array, n)
real :: array(n:)
Or if the subroutine in question is always supposed to work with
a lower bound of -1, you can just hardwire that instead of passing it,
as in
subroutine sub(array)
real :: array(-1:)
--
Richard Maine
[log in to unmask]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|