Richard Maine wrote:
> 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.
Not quite. Fortran compilers often do aliasing-type analysis on pointers, so
they may be perfectly able to prove that p cannot point to any part of x and
then proceed to optimize. With C_LOC there is no real pointer assignment, so
this was my concern. The same would happen if x was never involved in any
pointer assignments, or if the call to c_routine is the first thing that
happens in the program. Should the compiler still assume that the value of x
can be modified by the called subroutine? You are saying yes, it
seems...This seems big overkill to me, but you are right, regulating this is
virtually impossible.
In any case, you have answered my question.
Thanks,
Aleksandar
|