[J3] Question on parent component naming
Bader, Reinhold
Reinhold.Bader at lrz.de
Tue Apr 9 15:25:59 UTC 2024
Dear Vipul,
Yes, in this simple case your suggestion is an easy workaround. In a more complex type, this would be more complicated to handle,
hence the use of a parent type structure constructor. The latter might also be overloaded, e.g. due to privatization of components.
Regards,
Reinhold
Von: Vipul Parekh <parekhvs at gmail.com>
Gesendet: Dienstag, 9. April 2024 16:56
An: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Bader, Reinhold <Reinhold.Bader at lrz.de>
Betreff: Re: [J3] Question on parent component naming
On Mon, Apr 8, 2024 at 10:22 AM Bader, Reinhold via J3 <j3 at mailman.j3-fortran.org<mailto:j3 at mailman.j3-fortran.org>> wrote:
..
Any opinions?
Hello Reinhold,
Apologies - even though you asked everyone on the distribution list to ignore your last email, most of us do not have a "Neuralyzer" to erase memory! :-))
That is, your point, "The question from my point of view simply was: what is the correct way to write the code?" stays etched!!
So with that in mind, re: your question in your original email "Any opinions?" why not simply do as follows which removes from consideration any complication due to renaming :
o_my_t%p => o_my_t%data
Thus please consider the following variant of your program with a block introduced for data output, the program using two processors produces output as per my expectations. Do all the 4 processors you are studying concur with this? If yes, this can be conforming way to write code that is portable across conformant processors. Additionally, I expect this will be a clearer instruction for any readers of said code who can also be a program author in a future incarnation and who may get confused with options (x) and (y)!
MODULE mod
TYPE :: t
REAL, POINTER :: p(:) => null()
END TYPE
END MODULE
PROGRAM ref_parent
USE mod, my_t => t
TYPE, EXTENDS(my_t) :: td
REAL :: data(3)
END TYPE
TYPE(td), TARGET :: o_my_t
! o_my_t%my_t = my_t(o_my_t%data) ! (x)
! o_my_t%t = my_t(o_my_t%data) ! (y)
o_my_t%p => o_my_t%data ! (z)
block
use, intrinsic :: iso_c_binding, only : c_loc, I8 => c_intptr_t
print "(g0,z0)", "Address in memory of o_my_t%p: ", transfer( source=c_loc(o_my_t%p), mold=1_i8 )
print "(g0,z0)", "Address in memory of o_my_t%data: ", transfer( source=c_loc(o_my_t%data), mold=1_i8 )
print *, "Is associated( pointer=o_my_t%p, target=o_my_t%data )? ", &
associated( pointer=o_my_t%p, target=o_my_t%data ), "; expected is T"
end block
END PROGRAM
An output from one processor:
C:\temp>gfortran -ffree-form p.f -o p.exe
C:\temp>p.exe
Address in memory of o_my_t%p: 7FF7DE52E080
Address in memory of o_my_t%data: 7FF7DE52E080
Is associated( pointer=o_my_t%p, target=o_my_t%data )? T ; expected is T
Regards,
Vipul Parekh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20240409/766d6d5a/attachment.htm>
More information about the J3
mailing list