Apologies if I revive this thread. I have a case where, for storage reasons, I need to point to a derived type component from another component, this way:
type :: container
type(surface) :: wall ! should this be a pointer?
type(wall_function) :: b_layer
end type
type :: wall_function
type(surface), pointer :: wall => null() ! => container%wall
[...]
end type
The reason wall is just referenced from inside the wall_function is that it’s a large object, duplication is not an option. How can I initialize it? target in a dummy argument is not valid, because the upstream variable is a derived type component with no target attribute (verified - it does):
subroutine init_b_layer(this,wall)
type(wall_function) :: this
type(surface), intent(in), target :: wall
this%wall => wall ! illegal: target goes out of scope after subroutine
end subroutine
so, should I declare the upstream type(surface) to be a pointer instead? That would significantly complicate the derived type handling though. If there are better options, please let me know I’d be glad to learn!