From: Thomas Koenig on
If I store something through a pointer dummy argument, is it OK if
this modifies data accessible through another pointer dummy argument?

Here's some example code:

module m
implicit none
contains
subroutine foo(a,b)
real, dimension(:), pointer :: a,b
a(1) = 1.0
b(1) = 2.0
end subroutine foo
end module m

program main
use m
implicit none
real, dimension(:), pointer :: a,b
real, dimension(2), target :: v

a => v
b => v

call foo(a,b)
print *,v(1)
end program main

I thought there was an old thread about this, but have been unable
to find it.
From: fj on
On 13 mai, 18:51, Thomas Koenig <tkoe...(a)netcologne.de> wrote:
> If I store something through a pointer dummy argument, is it OK if
> this modifies data accessible through another pointer dummy argument?
>
> Here's some example code:
>
> module m
>   implicit none
> contains
>   subroutine foo(a,b)
>     real, dimension(:), pointer :: a,b
>     a(1) = 1.0
>     b(1) = 2.0
>   end subroutine foo
> end module m
>
> program main
>   use m
>   implicit none
>   real, dimension(:), pointer :: a,b
>   real, dimension(2), target :: v
>
>   a => v
>   b => v
>
>   call foo(a,b)
>   print *,v(1)
> end program main
>
> I thought there was an old thread about this, but have been unable
> to find it.

One calls that "aliasing" and the FORTRAN norm indicates clearly that
this is strictly forbidden in that situation.

Aliasing is only authorized with input arguments (for instance
declared with INTENT(in)) and becomes "standard non conforming" when
the subroutine tries to modify one of these arguments. The result is
generally unpredictable.

From: Richard Maine on
fj <francois.jacq(a)irsn.fr> wrote:

> On 13 mai, 18:51, Thomas Koenig <tkoe...(a)netcologne.de> wrote:
> > If I store something through a pointer dummy argument, is it OK if
> > this modifies data accessible through another pointer dummy argument?

> One calls that "aliasing" and the FORTRAN norm indicates clearly that
> this is strictly forbidden in that situation.

I beg to disagree, Alas I don't have a copy of the standard handy here
in the airport (and I don't feel like browing to an online one), so I
can't give citations. You have overlooked the fact that both the dummy
arguments are pointers. Yes, it makes a difference. Aliasing of pointers
is pretty much the norm; they are treated differently.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: fj on
On 13 mai, 20:02, nos...(a)see.signature (Richard Maine) wrote:
> fj <francois.j...(a)irsn.fr> wrote:
> > On 13 mai, 18:51, Thomas Koenig <tkoe...(a)netcologne.de> wrote:
> > > If I store something through a pointer dummy argument, is it OK if
> > > this modifies data accessible through another pointer dummy argument?
> > One calls that "aliasing" and the FORTRAN norm indicates clearly that
> > this is strictly forbidden in that situation.
>
> I beg to disagree, Alas I don't have a copy of the standard handy here
> in the airport (and I don't feel like browing to an online one), so I
> can't give citations. You have overlooked the fact that both the dummy
> arguments are pointers. Yes, it makes a difference. Aliasing of pointers
> is pretty much the norm; they are treated differently.

Ah, right! I did not notice the keyword "pointer" in the declaration
of the arguments of the routine foo.

Anyway, I have a question : does it mean that the two following
subroutines would behave differently ?

module m
implicit none
contains
subroutine foo1(a,b)
real, dimension(:), pointer :: a,b
a(1) = 1.0
b(1) = 2.0
end subroutine foo1
subroutine foo2(a,b)
real, dimension(:) :: a,b
a(1) = 1.0
b(1) = 2.0
end subroutine foo2
end module m

>
> --
> Richard Maine                    | Good judgment comes from experience;
> email: last name at domain . net | experience comes from bad judgment.
> domain: summertriangle           |  -- Mark Twain

From: Craig Powers on
fj wrote:
>
> Anyway, I have a question : does it mean that the two following
> subroutines would behave differently ?
>
> module m
> implicit none
> contains
> subroutine foo1(a,b)
> real, dimension(:), pointer :: a,b
> a(1) = 1.0
> b(1) = 2.0
> end subroutine foo1
> subroutine foo2(a,b)
> real, dimension(:) :: a,b
> a(1) = 1.0
> b(1) = 2.0
> end subroutine foo2
> end module m

The subroutines, their callers, or both might behave differently under
the hood, although for identical usage (assuming standard-conformance in
the case of the second) I don't believe it should be reflected in any
user-visible way other than potentially timing.