(j3.2006) Should parent component have the accessibility of the parent type?
Daniel C Chen
cdchen
Mon Jan 25 23:16:10 EST 2016
Hi Malcolm,
Thanks very much for the detailed explanation! It all makes sense now.
Daniel
XL Fortran Development - IBM Toronto Software Lab
Phone: 905-413-3056
Tie: 969-3056
Email: cdchen at ca.ibm.com
http://www.ibm.com/software/awdtools/fortran/xlfortran
From: "Cohen Malcolm" <malcolm at nag-j.co.jp>
To: "fortran standards email list for J3"
<j3 at mailman.j3-fortran.org>
Date: 01/25/2016 22:02
Subject: Re: (j3.2006) Should parent component have the accessibility of
the parent type?
Sent by: j3-bounces at mailman.j3-fortran.org
Hi Daniel,
<<<
Module AB
private
Type A_t
Integer i
End type
Type, extends(A_t) :: B_t
End type
Public B_t
End module
Module C
Use AB
Type, extends(B_t) :: C_t
End type
Contains
Subroutine sub(this)
Type(C_t) :: this
This%B_t%A_t%i = 4 !! NOT allowed
This%B_t%i = 4 !! Allowed
End subroutine
End module
>>>
A_T is private, therefore it is not accessible ouside of AB.
Component I is public therefore it is accessible outside of AB.
So the comments are correct.
>Is there any case that a parent component should not be accessible at all?
I don?t understand this question, since the parent component is already
inaccessible in this example. This is how it is meant to be. Component I
is public so it is accessible, if you want component I not to be public you
should specify that! The accessibility of a type (A_T) and its components
(I) are individually specifiable and not connected in any way.
This is useful in a number of scenarios. For example, when extending via
two steps, so that the private extension was internal to the module and not
cluttering up the user?s view of the exported extension. E.g.
Module base
Type root
End Type
End Module
Module extension
Use base
Type,Extends(root),Private :: mytype
Integer a,b
End Type
Type,Extends(mytype) :: type
Integer c
End Type
...
End Module
Outside of the module EXTENSION, it looks like type TYPE was produced like
this:
Type,Extends(root) :: type
Integer a,b,c
End Type
and that means that ?mytype? does not appear in the component list, so the
user can have his own ?mytype? later on, without it conflicting with the
EXTENSION module.
There are plausible reasons for wanting to be able to extend a type like
this without exporting the internal details of how it was done. For
example, one might want to act on the ?mytype? part as a whole separately
from the rest of the added components. I am sure people can think of other
reasons.
Another time when a private parent component is useful is when you are
adding private components:
Module E2
Use base
Type,Extends(root),Private :: mytype2
Integer,Private :: mya,myb
End Type
Type,Extends(root) :: type
Integer c
End Type
Type(type) :: x
...
End Module
If MYTYPE2 were public, then one could act on the private components of X
by using X%MYTYPE2. Having MYTYPE2 private prevents this, so one can only
act on X as a whole, or on the public component X%C.
Cheers,
--
........................Malcolm Cohen, Nihon NAG, Tokyo.
_______________________________________________
J3 mailing list
J3 at mailman.j3-fortran.org
http://mailman.j3-fortran.org/mailman/listinfo/j3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.j3-fortran.org/pipermail/j3/attachments/20160125/9d41ec29/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
Url : http://mailman.j3-fortran.org/pipermail/j3/attachments/20160125/9d41ec29/attachment-0001.gif
More information about the J3
mailing list