From what I gather, it's best to avoid any kind of aliasing in Fortran. What would be a proper way of implementing the following?
Say, I have two derived types: base_t and child_t, each one defined in its own separate module. child_t extends base_t (I want to model is-a relationship). base_t is an abstract type and has a deferred procedure, which it calls at some point. The child type must provide a definition for this procedure. The problem is that this procedure is supposed to change a private attribute of the base type which is not accessible to the child (add new coordinates to the coordinates array). I was going to pass it as an argument to this deferred procedure, but after reading the thread on aliasing and derived types (https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x/topic/597073) it seems like a bad idea. I originally posted this question there, but following FortranFan's comment I moved it to a separate thread. Next paragraph is my response to the comment.
The consumer is not supposed to be able to add new coordinates. Take a look at the simplified example I added below (tried to make it as short as possible). Generally, I'm trying to avoid a setter procedure, because it would be public, and would be accessible to anyone, which contradicts encapsulation principles.
Here's what a consumer is expected to do.
real, dimension(:), allocatable :: f class(base_t), allocatable :: b allocate(child_t::b) ! call b%init with some arguments. ! do some other work call b%compute_differential_operator(f)
And here's a base_t's module.
module base implicit none private public :: base_t type, abstract :: base_t private real, dimension(:,:), allocatable :: x integer :: num_bndr = 0 contains private procedure, public :: init ! creates initial x array, left it out in this example procedure, public :: compute_differential_operator procedure(create_boundary_particles_func_t), deferred :: create_boundary_particles end type base_t interface subroutine create_boundary_particles_func_t (this, x) import :: base_t implicit none class(base_t), intent(in) :: this real, dimension(:,:), allocatable, intent(in out) :: x ! aliasing would appear when calling this function end subroutine create_boundary_particles_func_t end interface contains subroutine compute_differential_operator (this, f) implicit none class(base_t), intent(in out) :: this real, dimension(:), intent(out) :: f integer :: num_non_bndr if (this%num_bndr <= 0) then num_non_bndr = size(this%x, 2) call this%create_boundary_particles(this%x) ! FIXME: ALIASING this%num_bndr = size(this%x, 2) - num_non_bndr else num_non_bndr = size(this%x, 2) - this%num_bndr end if ! Here we somehow fill f array based on the positions ! of regular and boundary particles. end subroutine compute_differential_operator end module base
P.S. I'm especially interested in the "right" way to do it, not a way. Suggestions on changing the code structure (like how to deal with the whole inheritance of a type with a private component thing) are welcome too. Thanks for any help in advance. I've originally learnt C++, and when it comes to things like OOP it is sometimes difficult to do things Fortran way rather than simply translate C++ principles into Fortran.
Fedor