From: Jim Xia on 13 May 2010 22:32 > > 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 answer is possible because "call foo2(ptr1, ptr1)" is illegal by Fortran standard. This is one of the most FAQ, and answered repeatedly, and yet forgotten by most people or wasn't understood in the first place. Here is what the standard says " 12.5.2.13 Restrictions on entities associated with dummy arguments 1 While an entity is associated with a dummy argument, the following restrictions hold. (1) Action that affects the allocation status of the entity or a subobject thereof shall be taken through the dummy argument. (2) If the allocation status of the entity or a subobject thereof is affected through the dummy argument, then at any time during the invocation and execution of the procedure, either before or after the allocation or deallocation, it shall be referenced only through the dummy argument. (3) Action that affects the value of the entity or any subobject of it shall be taken only through the dummy argument unless (a) the dummy argument has the POINTER attribute or (b) the dummy argument has the TARGET attribute, the dummy argument does not have INTENT (IN), the dummy argument is a scalar object or an assumed-shape array without the CONTI- GUOUS attribute, and the actual argument is a target other than an array section with a vector subscript. (4) If the value of the entity or any subobject of it is affected through the dummy argument, then at any time during the invocation and execution of the procedure, either before or after the definition, it may be referenced only through that dummy argument unless (a) the dummy argument has the POINTER attribute or (b) the dummy argument has the TARGET attribute, the dummy argument does not have INTENT (IN), the dummy argument is a scalar object or an assumed-shape array without the CONTI- GUOUS attribute, and the actual argument is a target other than an array section with a vector subscript." The text is pretty hard to read, but basically it says if two dummy arguments are referring to the same entity, you'd better NOT to modify their values, allocation or association status. The ONLY exceptions are 1.) the POINTER dummy whose value can be changed, 2.) a modifiable TARGET dummy argument associated with a TARGET actual argument (i.e. no copy-in situation). I would steer clear off overlapping dummy arguments in code. Cheers, Jim
First
|
Prev
|
Pages: 1 2 Prev: use of EQUIVALENCE for a dynamical assignment of data Next: Between hard code writing hours |