[J3] US21 enum constructor
Malcolm Cohen
malcolm at nag-j.co.jp
Mon Oct 4 00:31:21 UTC 2021
Hi John,
I disagree with your conjecture of invalidity. I note you provided no quotes to back it up!
This NOTE is for interoperable enums. Not for enumerator types. Interoperable enums act pretty much just like C enums, that is their purpose. For example, the first paragraph of the subclause you are reading states
“An interoperable enumerator is a named integer constant;”
and in p6 (about the enum constructor) we have
“The value of expr shall be representable in objects of that type”
It is possible that 12345 might not be representable, but it is highly likely to be. I suppose we could add an extra enum “big=99999” to the example to force the issue.
Personally I am not a fan of the proliferation of BOZ constants, but others are, and the text reflects their preferences. And in this case it seems reasonable.
I take your point re scalar. The <expr> in R765 etc should probably be <scalar-expr>, viz lines 13, 14 and 16.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of John Reid via J3
Sent: Monday, October 4, 2021 7:32 AM
To: fortran standards email list for J3 <j3 at j3-fortran.org>
Cc: John Reid <John.Reid at stfc.ac.uk>
Subject: [J3] US21 enum constructor
J3,
In NOTE 6 on page 90 of 21-007r2, the enum type myenum is defined thus
Enum,Bind(C) :: myenum
Enumerator :: one=1, two, three
End Enum
and is later used in two enum constructors thus
Type(myenum) :: y = myenum(12345) ! Using the constructor.
Type(myenum) :: x2 = myenum(two) ! Constructor not needed but valid.
I see both of these as invalid. I think the first is invalid because
12345 in not the value of an enumerator of the type myenum and the
second is invalid because two is the name of an enumerator instead of an
integer expression or boz constant. Do you agree?
Also, I am not happy with the definitive text at [89:13-16]:
"R765 enum-constructor is enum-type-spec ( expr )
C7113 The expr in an enum-constructor shall be of type integer or be a
boz-literal-constant.
An enum constructor produces a scalar value of the specified type, with
the specified internal representation. The value of expr shall be
representable in objects of that type."
It is not clear to me exacly how a boz-literal-constant as the expr of
an enum constructor is interpreted. Why do we need this at all? The user
can use INT to convert a boz constant. Also we need to say that expr is
scalar here. I suggest changing "expr" in R765 to "scalar-int-expr",
deleting C7113, and changing the para that follows to
"An enum constructor produces the enumerator of the specified type whose
value is equal to that of the scalar-int-expr."
Note that we talk of the value of an enumerator in the previous para
[89:4-12].
Comments, please.
John.
Disclaimer
The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: 30 St. Giles, Oxford, OX1 3LE, United Kingdom. Please see our Privacy Notice <https://www.nag.co.uk/content/privacy-notice> for information on how we process personal data and for details of how to stop or limit communications from us.
This e-mail has been scanned for all viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20211004/458b7830/attachment.htm>
More information about the J3
mailing list