On Wed, 2011-04-27 at 14:17 -0700, Neil N. Carlson wrote:
> On Wed, 2011-04-27 at 13:59 -0700, Van Snyder wrote:
> > Your actual argument is a pointer, so it has the TARGET attribute.
> > Without the POINTER attribute, it needs the TARGET attribute if you
> > expect any associations with the dummy argument (and thereby with the
> > actual argument) to persist after INIT returns. I assume you want the
> > association this%x => x to persist.
> >
> > Just change the dummy argument X in INIT from POINTER to TARGET and
> > your code works (at least in Intel (R) Fortran 12.0-1230). If the dummy
> > argument is neither a pointer nor allocatable, the actual argument
> > doesn't have to be polymorphic.
>
> Right. But for the association to persist the actual must either be a
> pointer or have the target attribute as you noted, however this isn't
> required and so this interface is easily misused and the compiler isn't
> going to catch it. That's why I shy away from this.
If the assignment in INIT were performed inline, the target would be
required to have either the TARGET or POINTER attribute, and the
compiler would be required detect this. It might not detect the case
where the pointer assignment occurs in a subroutine -- because it's not
required. If the actual argument has neither the POINTER nor TARGET
attribute, and there is a pointer associated with it somewhere, the
compiler won't know that there is a potential aliasing problem. For
example, it might keep the target (or pieces of it) in a register, and
not realize that changes might have occurred by way of a pointer
associated with it. So, in either case, your target better have either
the POINTER or TARGET attribute.
Pay your money and take your choice: Give the POINTER attribute to the
actual argument (which requires the same declared type for actual and
dummy arguments), or give the TARGET attribute to the actual argument.
12.5.2.5p1-2 in the F08 standard could be relaxed a tiny bit so as not
to apply to pointer dummy arguments with the INTENT(IN) attribute. In
that case, the scenario described in Note 12.27 can't happen.
> > > (3) Section C.9.4 (section 1, case (ii)) suggests making the dummy a
> > > pointer with INTENT(IN) and the actual a non-pointer with the target
> > > attribute (compiler enforced?) The compiler I'm using won't swallow
> > > this. Either I've misunderstood this, or this feature (new to 2008 I
> > > believe) isn't implement yet.
>
> Did I understand C.9.4 correctly? Can the dummy be an INTENT(IN)
> pointer and the actual a non-pointer with a compiler-enforced target
> attribute? The answer is somewhat moot, since I this is F2008 and
> there's not much support for that yet.
First, C.9.4 is informative, not normative. But, yes, Fortran 2008 does
allow an intent(in) pointer dummy argument to correspond to a
non-pointer actual argument, provided the actual argument has the TARGET
attribute. The compiler might or might not enforce the requirement for
the actual argument to have the TARGET attribute. 12.5.2.7p2 in the F08
standard is an ordinary paragraph, not a constraint. As such, it is
requirement on the program, not the processor. It could conceivably be
a constraint, since explicit interface is required if a procedure has a
dummy argument with the POINTER attribute (12.4.2.2p1(2)(a)) -- but it
isn't a constraint.
> -Neil
>
|