digitalmars.D - manifest enum
- John Reimer (27/27) Jan 01 2008 This may have been asked before, but the documentation isn't clear:
- John Reimer (5/22) Jan 01 2008 correction: "...and it's address /can't/ be taken (which is easy to
- Derek Parnell (14/51) Jan 01 2008 There is no difference between a group of manifest constants and a singl...
- John Reimer (17/34) Jan 01 2008 Yep, I read that.
- Sean Kelly (7/38) Jan 01 2008 'enum' is now basically a storage class in addition to an enumeration
- John Reimer (5/14) Jan 01 2008 I'll have to test it out and see (that must have been based on earlier
- Sean Kelly (26/45) Jan 01 2008 The end of the scope I think. And I should qualify this by saying I
- Walter Bright (2/8) Jan 01 2008 No, it's not a storage class and that won't work.
- Sean Kelly (3/12) Jan 03 2008 Oops, my mistake.
- John Reimer (6/18) Jan 01 2008 Okay, I was jumping the gun. It seems anonymous enums are synonymous
- Derek Parnell (9/10) Jan 01 2008 I don't think anyone has accused D of being too well documented ;-)
- Russell Lewis (13/13) Jan 02 2008 Have a look at this code:
- Janice Caron (4/9) Jan 02 2008 I don't think that will compile. The whole point of naming an enum is
- Russell Lewis (6/18) Jan 02 2008 Sorry, right. So this:
This may have been asked before, but the documentation isn't clear: With the new enum in D 2.0, is there a difference between a singly declared manifest: enum i=4; and the anonymous enum block: enum { A = 1.2f, B = 2L, C = 3 } The docs say that the singly declared manifest enum is not an lvalue and it's address can be taken (which is eaasy to understand). However, does this apply to the anonymous enum in the second case also? Put another way, does the second case classify as a /list/ of manifest enums? If the two are not the same... then a I guess a manifest enum has to be declared every line with "enum" in front which would become rather painfully redundant given that other structures in the language allow you to group several declarations in a block (extern). On the other hand if an anonymous enum block /is/ the same as a single manifest constant, then it becomes confusing and hard to differentiate the old enum type in a listing from the manifest enums. Maybe this was one of the arguments against it in earlier discussions? I can settle for the name "enum", but it does seem to add a unusual level of confusion. Granted I'm probably bringing up something that's been hashed over in previous discussions already. -JJR
Jan 01 2008
John Reimer wrote:This may have been asked before, but the documentation isn't clear: With the new enum in D 2.0, is there a difference between a singly declared manifest: enum i=4; and the anonymous enum block: enum { A = 1.2f, B = 2L, C = 3 } The docs say that the singly declared manifest enum is not an lvalue and it's address can be taken (which is eaasy to understand).correction: "...and it's address /can't/ be taken (which is easy to understand)." Argh! -JJR
Jan 01 2008
On Tue, 01 Jan 2008 12:02:04 -0800, John Reimer wrote:This may have been asked before, but the documentation isn't clear: With the new enum in D 2.0, is there a difference between a singly declared manifest: enum i=4; and the anonymous enum block: enum { A = 1.2f, B = 2L, C = 3 } The docs say that the singly declared manifest enum is not an lvalue and it's address can be taken (which is eaasy to understand). However, does this apply to the anonymous enum in the second case also? Put another way, does the second case classify as a /list/ of manifest enums? If the two are not the same... then a I guess a manifest enum has to be declared every line with "enum" in front which would become rather painfully redundant given that other structures in the language allow you to group several declarations in a block (extern). On the other hand if an anonymous enum block /is/ the same as a single manifest constant, then it becomes confusing and hard to differentiate the old enum type in a listing from the manifest enums. Maybe this was one of the arguments against it in earlier discussions? I can settle for the name "enum", but it does seem to add a unusual level of confusion. Granted I'm probably bringing up something that's been hashed over in previous discussions already. -JJRThere is no difference between a group of manifest constants and a single manifest constant. enum x = 3; enum y = "four"; and enum {x = 3, y = "four"}; are semantically identical. The documenation says this ... "If there is only one member of an anonymous enum, the { } can be omitted". -- Derek Parnell Melbourne, Australia skype: derek.j.parnell
Jan 01 2008
YDerek Parnell wrote:There is no difference between a group of manifest constants and a single manifest constant. enum x = 3; enum y = "four"; and enum {x = 3, y = "four"}; are semantically identical. The documenation says this ... "If there is only one member of an anonymous enum, the { } can be omitted".Yep, I read that. But it wasn't clear to me that the following statement applied to anonymous enums also: "such declarations are not lvalues, meaning their address cannot be taken." The fact that both these statements were in a separate section titled "Manifest Constants" made it look like these were treated as an independent entity from "Anonymous Enums", the section just before it. Perhaps I should have inferred that the prhase "the { } can be omitted" indicated they were one and the same, but I still think it's somewhat unclearly documented. If anonymous enums and manifest constants are the same, then the section "Manifest Constants" should probably be removed and the sections merged. A reference can be made to the fact that these represent two different forms of manifest constants. Then the statement on lvalue would be taken to refer to both forms. -JJR
Jan 01 2008
John Reimer wrote:YDerek Parnell wrote:'enum' is now basically a storage class in addition to an enumeration specifier, so you can even do this I believe: enum: a = 1; b = 2; SeanThere is no difference between a group of manifest constants and a single manifest constant. enum x = 3; enum y = "four"; and enum {x = 3, y = "four"}; are semantically identical. The documenation says this ... "If there is only one member of an anonymous enum, the { } can be omitted".Yep, I read that. But it wasn't clear to me that the following statement applied to anonymous enums also: "such declarations are not lvalues, meaning their address cannot be taken." The fact that both these statements were in a separate section titled "Manifest Constants" made it look like these were treated as an independent entity from "Anonymous Enums", the section just before it.
Jan 01 2008
Sean Kelly wrote:'enum' is now basically a storage class in addition to an enumeration specifier, so you can even do this I believe: enum: a = 1; b = 2; SeanI'll have to test it out and see (that must have been based on earlier discussions?). But doing that would seem strange... and maybe a little ambiguous? What marks the end of the "enum:" specifier sequence for manifest constants then?
Jan 01 2008
John Reimer wrote:Sean Kelly wrote:The end of the scope I think. And I should qualify this by saying I haven't tried it, but it would be consistent with what Walter has said in the past. So far, the only slightly tricky thing I've found is where the new behavior overlaps the old behavior: enum { a = byte.max } In D 1.0, the type of 'a' is int, and in D 2.0 the type is 'byte', because the type in D 2.0 is inferred from the initializer. So for portability, such declarations should always be specified with a type qualifier: enum : int { a = byte.max } Fortunately, implicit narrowing conversions seem to be disallowed in D 1.0 here, so this is illegal and thus not a portability problem: enum { a = long.max } It's legal in D 2.0 however, and the resulting type is 'long', as you'd expect. Sean'enum' is now basically a storage class in addition to an enumeration specifier, so you can even do this I believe: enum: a = 1; b = 2; SeanI'll have to test it out and see (that must have been based on earlier discussions?). But doing that would seem strange... and maybe a little ambiguous? What marks the end of the "enum:" specifier sequence for manifest constants then?
Jan 01 2008
Sean Kelly wrote:'enum' is now basically a storage class in addition to an enumeration specifier, so you can even do this I believe: enum: a = 1; b = 2;No, it's not a storage class and that won't work.
Jan 01 2008
Walter Bright wrote:Sean Kelly wrote:Oops, my mistake. Sean'enum' is now basically a storage class in addition to an enumeration specifier, so you can even do this I believe: enum: a = 1; b = 2;No, it's not a storage class and that won't work.
Jan 03 2008
John Reimer wrote:On the other hand if an anonymous enum block /is/ the same as a single manifest constant, then it becomes confusing and hard to differentiate the old enum type in a listing from the manifest enums. Maybe this was one of the arguments against it in earlier discussions? I can settle for the name "enum", but it does seem to add a unusual level of confusion. Granted I'm probably bringing up something that's been hashed over in previous discussions already. -JJROkay, I was jumping the gun. It seems anonymous enums are synonymous with manifest constants, period -- singly or block declared. I can live with that. I suppose there shouldn't be any confusion. Although, I think the docs could clearer as indicated in my last post. -JJR
Jan 01 2008
On Tue, 01 Jan 2008 14:37:11 -0800, John Reimer wrote:Although, I think the docs could clearer as indicated in my last post.I don't think anyone has accused D of being too well documented ;-) But there is only one Walter and everything, including documentation improvements, must go through him as the final process step. -- Derek Parnell Melbourne, Australia skype: derek.j.parnell
Jan 01 2008
Have a look at this code: enum Named { uint foo = 1; bar = 2; }; enum /* anonymous */ { uint fred = 1; wilma = 2; }; In the above, unless I'm mistaken, typeof(bar) is uint, but typeof(wilma) is int. Right? So just naming a previously unnamed enum changes the types of the elements? Ick.
Jan 02 2008
On 1/2/08, Russell Lewis <webmaster villagersonline.com> wrote:Have a look at this code: enum Named { uint foo = 1; bar = 2; };I don't think that will compile. The whole point of naming an enum is to create a new type, so that you can subsequently declare: Named x;
Jan 02 2008
Janice Caron wrote:On 1/2/08, Russell Lewis <webmaster villagersonline.com> wrote:Sorry, right. So this: enum Named { foo = 1U; bar = 2; };Have a look at this code: enum Named { uint foo = 1; bar = 2; };I don't think that will compile. The whole point of naming an enum is to create a new type, so that you can subsequently declare: Named x;
Jan 02 2008