D - [Suggestion] Specify underlying type of enum
- Stewart Gordon (22/22) Apr 14 2004 A nice idea would be a syntax like this
- Vathix (2/8) Apr 14 2004 It's already supported.
- Stewart Gordon (10/19) Apr 15 2004 I should know not to rely on the documentation by now! Thanks for
- J C Calvarese (7/29) Apr 15 2004 I would have sworn this was mentioned in the spec, but I can't find it
- Walter (4/11) Apr 16 2004 I thought it was there too, but it isn't. So I fixed it.
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
Stewart Gordon wrote:A nice idea would be a syntax like this enum QWERT : uint { ... }It's already supported.
Apr 14 2004
Vathix wrote:Stewart Gordon wrote: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.A nice idea would be a syntax like this enum QWERT : uint { ... }It's already supported.
Apr 15 2004
Stewart Gordon wrote:Vathix wrote: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!Stewart Gordon wrote: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.A nice idea would be a syntax like this enum QWERT : uint { ... }It's already supported.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
"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.I'll fix that, too.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.
Apr 16 2004