manifest enum

Derek Parnell derek at psych.ward
Tue Jan 1 13:47:56 PST 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.
> 
> -JJR

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".

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list