------- Comment #5 from jv244 at cam dot ac dot uk  2009-05-19 11:54 -------
(In reply to comment #3)
> Does
> 
>     SUBROUTINE S(I1,IP)
>       INTEGER,INTENT(IN) :: I1
>       INTEGER, POINTER :: IP
>     END SUBROUTINE S
> 
> allow that S stores the pointer to I1 to global memory?

this is not a very Fortran-ish way to express this, and I'm not very C-ish, but
the answer is no (I don't think you can obtain the address of I1 in S1 using
standard conforming Fortran, and certainly there is no guarantee at all that
you get the address of I1 in F1). Even if you get the address of I1, no way
you're allowed to change the value of I1, either in S1, or in any subroutine
called subsequently.

The important thing is not so much that (I believe), but the fact that Fortran
guarantees that in the caller where I1 is defined (i.e. F1), nothing else can
alias that variable.

> I think that the easiest way to improve Fortran code generation is to _not_
> pass INTENT(IN) arguments by reference but by value (at least for scalar
> types).

I believe that his is some kind of misunderstanding. It is not because the FE
generates some code that is call by reference that his is actually what the
rules are. AFAICT, it would be equally valid for a Fortran implementation to
copy in and copy out the data (i.e. the address of the variable in the caller
is of no importance in the callee).

I think it would be worthwhile to discuss this once with the group of
gcc-people that know both Fortran and the middle-end really well (I hope this
is a non-zero subset :-)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40194

Reply via email to