> unfortunately values declared in a user-defined type cannot have the PARAMETER attribute, which might make it a bit more elegant.
I did ask for this earlier here:
https://github.com/j3-fortran/fortran_proposals/issues/110
The use of the PARAMETER attribute would make things more safe.
But even without the PARAMETER attribute, we can effectively use integer based enums with the compilers already. Integer based enums are essentially for implementing distributed objects with Coarray Fortran because we can use the values with atomic coarrays. I am currently working on a channel implementation using coarrays, code snippets below are taken from that: John’s last syntax example will not work for this, and the enum type component must be declared above CONTAINS yet, of course. The enum type itself can even be extended in Fortran, which makes the use of such enum types very flexible and efficient as we may use them differently at multiple levels.
!************************
!**** enumeration types: ***
!************************
!*** Enum_FragmentedMethodChannel1Status:
type, extends(OOOPchnl00_ChannelStatus_EnumDef), private :: OOOPfrob03_00_Channel1Status_EnumDef
! (values below 10000000 are reserved for the channel itself here)
!
! values for controlling the execution flow:
integer(kind=OOOGglob_kint) :: InitiateFragmentedMethod3 != 10000000
integer(kind=OOOGglob_kint) :: ReadyToStartFragmentedMethod3 != 11000000
integer(kind=OOOGglob_kint) :: StartFragmentedMethod3 != 12000000
integer(kind=OOOGglob_kint) :: SendCurrentTestValue != 13000000
integer(kind=OOOGglob_kint) :: AdjustTestValueToMaxTestValue != 14000000
integer(kind=OOOGglob_kint) :: FinishedFragmentedMethod3 != 15000000
integer(kind=OOOGglob_kint) :: ExitFragmentedMethod3 != 16000000
!
! always required:
integer(kind=OOOGglob_kint) :: Enum_MaxValue != 17000000
end type OOOPfrob03_00_Channel1Status_EnumDef
!********************
!*** type definition: ***
!********************
type, extends(OOOPfrob03_00_objBaseFragmentedMethod3), abstract, public :: OOOPfrob03_01_objFragmentedMethod3_CE
private
!*****
! enumeration type members:
! (values below 10000000 are reserved for the channel itself):
type (OOOPfrob03_00_Channel1Status_EnumDef), public :: Enum_Channel1Status &
= OOOPfrob03_00_Channel1Status_EnumDef (1000000,2000000,3000000, &
10000000,11000000, 12000000,13000000,14000000,15000000,16000000,17000000)
!*****
! local members:
!*****
! coarray component members: (not recommended if channels are in use)
!*****
contains
private
procedure, public :: FragmentedMethod3_CE => OOOPfrob03_01_FragmentedMethod3_CE
end type OOOPfrob03_01_objFragmentedMethod3_CE