www.digitalmars.com         C & C++   DMDScript  

D - [Suggestion] Specify underlying type of enum

reply Stewart Gordon <smjg_1998 yahoo.com> writes:
A nice idea would be a syntax like this

	enum QWERT : uint {
		...
	}

This would create an enumerated type represented as a uint.  Of course 
any enum with an underlying type could be implicitly converted to that type.

Possible uses:

1. Defining an enum to wrap a set of constants used by an external API.

2. Creating collections of floating-point constants.

3. Guaranteeing the size of an enum to be constant, when this may be 
needed by e.g. a file format.

We might as well allow this with anonymous enums:

	enum : uint {
		...
	}

which would be a syntactic sugar for endless static const declarations.

The question is: Should a non-atomic type be allowed as an underlying 
type?  Maybe that depends on the kind of type.

Stewart.

-- 
My e-mail is valid but not my primary mailbox.  Please keep replies on 
on the 'group where everyone may benefit.
Apr 14 2004
parent reply Vathix <vathix dprogramming.com> writes:
Stewart Gordon wrote:
 A nice idea would be a syntax like this
 
     enum QWERT : uint {
         ...
     }
 

It's already supported.
Apr 14 2004
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Vathix wrote:

 Stewart Gordon wrote:
 
 A nice idea would be a syntax like this

     enum QWERT : uint {
         ...
     }

It's already supported.

I should know not to rely on the documentation by now! Thanks for pointing this out. And I've noticed it's even used in windows.d. Strangely, it allows me to declare one using a struct or union type, but all attempts to put values into one, or access them, seem to totally confuse the compiler. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on on the 'group where everyone may benefit.
Apr 15 2004
parent reply J C Calvarese <jcc7 cox.net> writes:
Stewart Gordon wrote:
 Vathix wrote:
 
 Stewart Gordon wrote:

 A nice idea would be a syntax like this

     enum QWERT : uint {
         ...
     }

It's already supported.

I should know not to rely on the documentation by now! Thanks for pointing this out. And I've noticed it's even used in windows.d.

I would have sworn this was mentioned in the spec, but I can't find it anywhere. I wonder if it used to be in the spec, but I couldn't even find it in the old PDF snapshots. How odd!
 
 Strangely, it allows me to declare one using a struct or union type, but 
 all attempts to put values into one, or access them, seem to totally 
 confuse the compiler.
 
 Stewart.

-- Justin http://jcc_7.tripod.com/d/
Apr 15 2004
parent "Walter" <walter digitalmars.com> writes:
"J C Calvarese" <jcc7 cox.net> wrote in message
news:c5nh8k$1hf3$1 digitaldaemon.com...
 I would have sworn this was mentioned in the spec, but I can't find it
 anywhere. I wonder if it used to be in the spec, but I couldn't even
 find it in the old PDF snapshots. How odd!

I thought it was there too, but it isn't. So I fixed it.
 Strangely, it allows me to declare one using a struct or union type, but
 all attempts to put values into one, or access them, seem to totally
 confuse the compiler.


I'll fix that, too.
Apr 16 2004