Thread overview
enum : type ???
Apr 09, 2002
Russ Lewis
Apr 09, 2002
Walter
Apr 09, 2002
OddesE
Apr 09, 2002
Russ Lewis
Apr 09, 2002
Walter
April 09, 2002
In com.d (in the newest D alpha source), there is this declaration:

enum : int
{
        S_OK = 0,
        S_FALSE = 0x00000001,
        NOERROR = 0,
        E_NOTIMPL     = 0x80004001,
        E_NOINTERFACE = 0x80004002,
        E_POINTER     = 0x80004003,
        E_ABORT       = 0x80004004,
        E_FAIL        = 0x80004005,
        E_HANDLE      = 0x80070006,
        CLASS_E_NOAGGREGATION = 0x80040110,
        E_OUTOFMEMORY = 0x8007000E,
        E_INVALIDARG  = 0x80070057,
        E_UNEXPECTED  = 0x8000FFFF,
}

Does D allow you to specify the underlying type of an enum, then?

--
The Villagers are Online! villagersonline.com

.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]


April 09, 2002
"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CB329ED.C26B55E7@deming-os.org...
> In com.d (in the newest D alpha source), there is this declaration:
>
> enum : int
> {
>         S_OK = 0,
>         S_FALSE = 0x00000001,
>         NOERROR = 0,
>         E_NOTIMPL     = 0x80004001,
>         E_NOINTERFACE = 0x80004002,
>         E_POINTER     = 0x80004003,
>         E_ABORT       = 0x80004004,
>         E_FAIL        = 0x80004005,
>         E_HANDLE      = 0x80070006,
>         CLASS_E_NOAGGREGATION = 0x80040110,
>         E_OUTOFMEMORY = 0x8007000E,
>         E_INVALIDARG  = 0x80070057,
>         E_UNEXPECTED  = 0x8000FFFF,
> }
>
> Does D allow you to specify the underlying type of an enum, then?

Yes!


April 09, 2002
"Walter" <walter@digitalmars.com> wrote in message news:a8vbhm$okj$1@digitaldaemon.com...
>
> "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CB329ED.C26B55E7@deming-os.org...
> > In com.d (in the newest D alpha source), there is this declaration:
> >
> > enum : int
> > {
> >         S_OK = 0,
> >         S_FALSE = 0x00000001,
> >         NOERROR = 0,
> >         E_NOTIMPL     = 0x80004001,
> >         E_NOINTERFACE = 0x80004002,
> >         E_POINTER     = 0x80004003,
> >         E_ABORT       = 0x80004004,
> >         E_FAIL        = 0x80004005,
> >         E_HANDLE      = 0x80070006,
> >         CLASS_E_NOAGGREGATION = 0x80040110,
> >         E_OUTOFMEMORY = 0x8007000E,
> >         E_INVALIDARG  = 0x80070057,
> >         E_UNEXPECTED  = 0x8000FFFF,
> > }
> >
> > Does D allow you to specify the underlying type of an enum, then?
>
> Yes!
>


I saw this too.
Is the omission of an enum name a hack, or
was it meant to be that way?
How do you define a parameter to a function
that takes such an enum, just as the same
type? So int in this case?
Could you explain this a bit more,
I am quite intrigued by it!


--
Stijn
OddesE_XYZ@hotmail.com
http://OddesE.cjb.net
_________________________________________________
Remove _XYZ from my address when replying by mail



April 09, 2002
OddesE wrote:

> I saw this too.
> Is the omission of an enum name a hack, or
> was it meant to be that way?
> How do you define a parameter to a function
> that takes such an enum, just as the same
> type? So int in this case?
> Could you explain this a bit more,
> I am quite intrigued by it!

I've used unnamed enums before as a shorthand to declare a set of constants.  It can be a lot easier to read, and gives the programmer a visual clue that all of the constants are related.  In this case, it would be a set of int constants.

--
The Villagers are Online! villagersonline.com

.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]


April 09, 2002
"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3CB33CD5.ACF32C8A@deming-os.org...
> OddesE wrote:
> > I saw this too.
> > Is the omission of an enum name a hack, or
> > was it meant to be that way?
> > How do you define a parameter to a function
> > that takes such an enum, just as the same
> > type? So int in this case?
> > Could you explain this a bit more,
> > I am quite intrigued by it!
> I've used unnamed enums before as a shorthand to declare a set of constants.  It can be a lot easier to read, and gives the programmer a visual clue that all of the constants are related.  In this case, it would be a set of int constants.

You're right. Specifying no name for the enum creates an "anonymous" enum, which is just a convenient way to create a bunch of integer constants in the enclosing scope. They'll be typed as an "int" (or whatever the enum base type is), not an enum.