Aleksandar Donev writes:
> Can someone point me to the location in the standard where it is
> basically said that TARGET variables can be modified by non-PURE
> procedures even if they do not appear as arguments to the procedure? I
> know this must be said somewhere, but am not sure where.
I wouldn't count on it being said anywhere. The standard doesn't
normally say things like that. There is, after all, an infinite
list of things that you are allowed to do. It is, I hope, obvious
that there is a syntactic way to do this (many of them). It is if you
were *NOT* allowed to do this that you'd expect to find a prohibition.
> interface
> subroutine c_routine(array), bind(c)
> type(c_ptr), value :: array
> end subroutine
> end interface
> real, dimension(100), target :: x
> call c_routine(C_LOC(x))
> x=x+1.0
>
> I am assuming that because of the TARGET attribute on x, the compiler
> will know that this routine may modify x even though x is not directly
> an argument, and thus may not do anything with x=x+1.0 until c_routine
> finishes. I cannot piece this from the standard though as I am missing
> some piece....
Yes, this appears safe. That is very much the kind of reason why
things have the target attribute in general - nothing new to C interop
in this. You'd have the same issue if you had a Fortran pointer,
pointed it at x, and then called some Fortran subroutine with that
pointer a an argument.
I don't think you are going to find it in so many words in the
standard. All you will find is that, yes, all this (including the
possibility that x might be modified during the call) is all legal,
and that therefore the compiler has to allow for the possibility.
--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
| -- Mark Twain
|