digitalmars.D - Anonymous enums specification
- Lennart Blanco <cokebuttle gmail.com> Jun 02 2011
- "Nick Sabalausky" <a a.a> Jun 02 2011
- Lennart Blanco <cokebuttle gmail.com> Jun 04 2011
--000e0cd52c901de53904a4c65aa4 Content-Type: text/plain; charset=UTF-8 Hi The page for enums specification http://www.digitalmars.com/d/2.0/enum.htmldefines enum body syntax as follows: EnumBody: ; { EnumMembers } Should it not be EnumBody: EnumMember ; { EnumMembers } or perhaps EnumBody: EnumMembers ; { EnumMembers } Otherwise, I can't quite grasp how following enums definitions are legal: enum X = 4; enum mega = 1024 * 1024, pi = 3.14, euler = 2.72, greet = "Hello"; (Both of the above enums are accepted by dmd v2.050). Regards, Lennart --000e0cd52c901de53904a4c65aa4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div>Hi</div><div><br></div><div>The page for enums specification <a href= =3D"http://www.digitalmars.com/d/2.0/enum.html">http://www.digitalmars.com/= d/2.0/enum.html</a> defines enum body syntax as follows:</div><div><br></di= v> <div>EnumBody:</div><div><span class=3D"Apple-tab-span" style=3D"white-spac= e:pre"> </span>;</div><div><span class=3D"Apple-tab-span" style=3D"white-sp= ace:pre"> </span>{ EnumMembers }</div><div><br></div><div>Should it not be<= /div> <div><br></div><div>EnumBody:</div><div><span class=3D"Apple-tab-span" styl= e=3D"white-space:pre"> </span>EnumMember ;</div><div><span class=3D"Apple-t= ab-span" style=3D"white-space:pre"> </span>{ EnumMembers }</div><div><br></= div> <div>or perhaps</div><div><br></div><div>EnumBody:</div><div><span class=3D= "Apple-tab-span" style=3D"white-space:pre"> </span>EnumMembers ;</div><div>= <span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>{ EnumMemb= ers }</div> <div><br></div><div>Otherwise, I can't quite grasp how following enums = definitions are legal:</div><div><br></div><div>enum X =3D 4;</div><div><br=</div><div>enum</div><div>=C2=A0 mega =3D 1024 * 1024,</div><div>=C2=A0 pi=
<div>=C2=A0 euler =3D 2.72,</div><div>=C2=A0 greet =3D "Hello";</= div><div><br></div><div>(Both of the above enums are accepted by dmd v2.050= ).</div><div><br></div><div>Regards,</div><div>Lennart</div> --000e0cd52c901de53904a4c65aa4--
Jun 02 2011
"Lennart Blanco" <cokebuttle gmail.com> wrote in message news:mailman.560.1307076213.14074.digitalmars-d puremagic.com...Hi The page for enums specification http://www.digitalmars.com/d/2.0/enum.htmldefines enum body syntax as follows: EnumBody: ; { EnumMembers } Should it not be EnumBody: EnumMember ; { EnumMembers } or perhaps EnumBody: EnumMembers ; { EnumMembers } Otherwise, I can't quite grasp how following enums definitions are legal: enum X = 4; enum mega = 1024 * 1024, pi = 3.14, euler = 2.72, greet = "Hello"; (Both of the above enums are accepted by dmd v2.050).
It's a poorly-named hack to allow people to create manifest constants. Ie, they're like immutable values, but they don't actually take up any space in memory. In other words, it works just like C's "#define SOME_VALUE 5": the value just gets substituted into the code wherever the name is found. But keep in mind that means it's not good to use that enum trick for arrays and AAs, because then a whole new array or AA will get allocated everywhere the enum is actually used.
Jun 02 2011
--000e0cd58e681733f504a4e9b2e0 Content-Type: text/plain; charset=UTF-8 On Fri, Jun 3, 2011 at 6:52 AM, Nick Sabalausky <a a.a> wrote:"Lennart Blanco" <cokebuttle gmail.com> wrote in message news:mailman.560.1307076213.14074.digitalmars-d puremagic.com...Hi The page for enums specification http://www.digitalmars.com/d/2.0/enum.html defines<http://www.digitalmars.com/d/2.0/enum.htmldefines>enum body syntax as follows: EnumBody: ; { EnumMembers } Should it not be EnumBody: EnumMember ; { EnumMembers } or perhaps EnumBody: EnumMembers ; { EnumMembers } Otherwise, I can't quite grasp how following enums definitions are legal: enum X = 4; enum mega = 1024 * 1024, pi = 3.14, euler = 2.72, greet = "Hello"; (Both of the above enums are accepted by dmd v2.050).
It's a poorly-named hack to allow people to create manifest constants. Ie, they're like immutable values, but they don't actually take up any space in memory. In other words, it works just like C's "#define SOME_VALUE 5": the value just gets substituted into the code wherever the name is found.
Yes, I understand how anonymous enums works. My question was regarding the D 2.0 specification document. To me it looks like the syntax for anonymous enums is missing in the specification. Only valid enum body definitions are empty body or a list of enum members, delimited with '{' abd '}'. /Lennart --000e0cd58e681733f504a4e9b2e0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote">On Fri, Jun 3, 2011 at 6:52 AM, Nick Sab= alausky <span dir=3D"ltr"><a a.a></span> wrote:<br><blockquote class= =3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd= ing-left:1ex;"> "Lennart Blanco" <<a href=3D"mailto:cokebuttle gmail.com">coke= buttle gmail.com</a>> wrote in message<br> news:mailman.560.1307076213.14074.digitalmars-d puremagic.com...<br> <div class=3D"im">> Hi<br> ><br> > The page for enums specification<br> </div>> <a href=3D"http://www.digitalmars.com/d/2.0/enum.htmldefines" ta= rget=3D"_blank">http://www.digitalmars.com/d/2.0/enum.html defines</a> enum= body syntax as<br> <div class=3D"im">> follows:<br> ><br> > EnumBody:<br> > ;<br> > { EnumMembers }<br> ><br> > Should it not be<br> ><br> > EnumBody:<br> > EnumMember ;<br> > { EnumMembers }<br> ><br> > or perhaps<br> ><br> > EnumBody:<br> > EnumMembers ;<br> > { EnumMembers }<br> ><br> > Otherwise, I can't quite grasp how following enums definitions are= legal:<br> ><br> > enum X =3D 4;<br> ><br> > enum<br> > =C2=A0mega =3D 1024 * 1024,<br> > =C2=A0pi =3D 3.14,<br> > =C2=A0euler =3D 2.72,<br> > =C2=A0greet =3D "Hello";<br> ><br> > (Both of the above enums are accepted by dmd v2.050).<br> ><br> <br> </div>It's a poorly-named hack to allow people to create manifest const= ants. Ie,<br> they're like immutable values, but they don't actually take up any = space in<br> memory. In other words, it works just like C's "#define SOME_VALUE= 5": the<br> value just gets substituted into the code wherever the name is found.<br></= blockquote><div><br></div><div>Yes, I understand how=C2=A0anonymous=C2=A0en= ums works. My question was regarding the D 2.0 specification document. To m= e it looks like the syntax for anonymous enums is missing in the specificat= ion. Only valid enum body definitions are empty body or a list of enum memb= ers, delimited with '{' abd '}'.</div> <div><br></div><div>/Lennart</div></div><br> --000e0cd58e681733f504a4e9b2e0--
Jun 04 2011









"Nick Sabalausky" <a a.a> 