[J3] [EXTERNAL] Re: Private enumerators

Vipul Parekh parekhvs at gmail.com
Sun Oct 20 01:52:02 EDT 2019

On Sat, Oct 19, 2019 at 4:42 PM Van Snyder via J3
<j3 at mailman.j3-fortran.org> wrote:
> ..
> When enumeration types were specified in 19-216r1, enumerators were
> class (1) names. We do not have any class (1) names for which
> <access-spec> is prohibited.
> ..


My point about <access-spec> pertained to *enumerators* in a declared
enumeration type, not the enumeration type itself.

The names of enumeration types are meant to be class (1) and thus the
syntax shall include <access-spec> for such a type.  But given the
consideration of class (2) for the enumerators the point is not to
have <access-spec> on enumerators.   See an example below where one
enumeration type called 'COLORS' has PUBLIC visibility whereas the
other named 'ALIGNMENT' is PRIVATE.  However the syntax for
enumerators themselves - such as RED, etc. in COLORS or LEFT, etc. in
ALIGNMENT - do not involve an <access-spec>, just as one does not
specify an <access-spec> on array elements.  Either the whole array
named constant such as RGB_CODES below is private or it can be made
public - same idea can be applied to enumerator members of enumeration

--- begin example ---
module ui_m

   use, intrinsic :: iso_fortran_env, only : I8 => int64


   enum, public :: COLORS  !<-- <access-spec> is Public
      enumerator :: RED
      enumerator :: GREEN
      enumerator :: BLUE
   end enum

   integer(I8), parameter :: RGB_CODES(*) = [ int(Z'FF0000', kind=I8), &
                                              int(Z'00FF00', kind=I8), &
                                              int(Z'0000FF', kind=I8) ]

   enum :: ALIGNMENT  !<-- <access-spec> is Private
      enumerator :: LEFT
      enumerator :: CENTER
      enumerator :: RIGHT
   end enum


end module
--- begin example ---

Hope this is clear.


More information about the J3 mailing list