Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
April 14, 2004 [Suggestion] Specify underlying type of enum | ||||
---|---|---|---|---|
| ||||
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.
|
April 14, 2004 Re: [Suggestion] Specify underlying type of enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon wrote:
> A nice idea would be a syntax like this
>
> enum QWERT : uint {
> ...
> }
>
It's already supported.
|
April 15, 2004 Re: [Suggestion] Specify underlying type of enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | 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. |
April 16, 2004 Re: [Suggestion] Specify underlying type of enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | 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/ |
April 17, 2004 Re: [Suggestion] Specify underlying type of enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | "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. |
Copyright © 1999-2021 by the D Language Foundation