digitalmars.D - Anonymous enums specification
- Lennart Blanco (25/25) Jun 02 2011 Hi
- Nick Sabalausky (9/32) Jun 02 2011 It's a poorly-named hack to allow people to create manifest constants. I...
- Lennart Blanco (6/46) Jun 04 2011 Yes, I understand how anonymous enums works. My question was regarding t...
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
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
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...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 '}'. /LennartHi 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.
Jun 04 2011