Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Max value of an ENUM

Reply
Thread Tools

Max value of an ENUM

 
 
James Kanze
Guest
Posts: n/a
 
      01-31-2011
On Jan 30, 4:47 pm, Andrea Crotti <(E-Mail Removed)> wrote:
> On Jan 30, 5:35 pm, Victor Bazarov <(E-Mail Removed)> wrote:


> > On 1/30/2011 10:27 AM, Andrea Crotti wrote:


> > >[..]
> > > And shouldn't be the enum an unsigned type by default?


> > No. Why should it? And what do you mean by "default"? There is no
> > such thing as "default" for user-defined types.


> An enumeration makes sense with an index negative?


The C++ keyword "enum" can be used to implement an enumeration,
but that isn't the only use. And even when it's used to
implement an enumeration, I occasionally use a special -1 value
for not set.

> I didn't mean in c++-0x where you can define what type you want, but
> in c++ pre 0x it's an int, right? And that's not an user-defined
> type...


In all C++, enum has always been a unique type, not an int. In
C++98 and C++03, there is an implementation defined underlying
integral type for each enum, which is large enough to hold all
of the values, but not gratuitously larger than an int. But
there is no implicit convertion from this type to the enum type.

In C, an enum also has a unique type, but the enum constants
have type int, the underlying type is required to be int, and
there is an implicit conversion of int to any enum type. (IIRC,
at least.)

--
James Kanze
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ENUM server for private ENUM kael UK VOIP 2 02-25-2007 11:54 AM
enum: display elements of an enum specified at runtime Jerminia Java 3 10-07-2005 10:08 PM
enum within an enum - Java 6 06-13-2005 12:51 AM
Including an enum within another enum, possible? mrhicks C Programming 2 06-10-2004 03:00 AM
How to enum an enum? Ernst Murnleitner C++ 5 11-13-2003 11:06 AM



Advertisments