Home > Archive > Fortran > September 2005 > Pointer
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Jason C 2005-09-26, 7:00 pm |
| If I have something like:
type some_type
integer, pointer:: stuff(:)
end type some_type
interface
subroutine sub1(param)
type(some_type), intent(in)::param
end subroutine sub1
end interface
then somewhere in the code:
type(some_type):: type_instance
allocate(type_instance%stuff(10000000))
call sub1(type_instance)
Can the compiler optimize the *stuff* array as read-only memory????
| |
| Michael Metcalf 2005-09-26, 7:00 pm |
|
"Jason C" <nightcom26@gmail.com> wrote in message
news:1127763436.934370.24420@g43g2000cwa.googlegroups.com...
>
>
> Can the compiler optimize the *stuff* array as read-only memory????
>
Well, what should happen is that the compiler will not allow pointer
assignment, allocation or deallocation. Whether assignment to the target is
allowed is ambiguous in f95, so some compilers allow it and some do not. In
f2003 the intent(in) does not apply to the target so ordinary assignment is
permitted. So, basically, the answer to your question is no (see also
"Fortran 95/2003 Explained", Section 5.9).
Regards,
Mike Metcalf
| |
| Richard Maine 2005-09-26, 7:00 pm |
| Jason C wrote:
> If I have something like:
>
> type some_type
> integer, pointer:: stuff(:)
> end type some_type
>
> interface
>
> subroutine sub1(param)
> type(some_type), intent(in)::param
> end subroutine sub1
>
> end interface
>
>
> then somewhere in the code:
>
> type(some_type):: type_instance
> allocate(type_instance%stuff(10000000))
> call sub1(type_instance)
>
>
> Can the compiler optimize the *stuff* array as read-only memory????
I'm not entirely sure what optimization this is you are hoping for. It
might be better if you were to ask the question in more concrete terms.
And, of course, any question about whether a compiler *WILL* optimize
something is very compiler-specific. A more general question is whether
the standard restricts things in such a way that compilers reasonably
could optimize something. In this case, depending on exactly what
optimization you are asking about (which really isn't clear to me), the
answer is probably "no". As a general rule, which has many exceptions
like all generalizations, pointers tend to screw up many opportunities
for optimization.
In particular here, the target of the pointer is not a subobject of the
derived type. Thus the intent(in) doesn't effectively prevent its value
from possibly changing. The intent(in) prevents you from pointing to a
different target, but it doesn't prevent the values stored in the same
target from changing.
So odds are that a compiler isn't going to be able to optimize based on
assumptions that the value won't change.
[Experimenting with a different newsreader - I'm not sure my signature
will show up correctly here.]
|
|
|
|
|