Thread: enumeration

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    enumeration

    Hi!

    Can anyone explain to me why is the range of "enum e2 { a=3, b=9 };" equal to 0:15?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Range?? What do you mean by range. In your case their is no range. Could you explain the problem a litte more detailed perhaps with a sample code?

  3. #3
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    This are the examples from the Stroustrup book:

    Code:
    enum e1 { dark, light }; // range 0:1
    enum e2 { a=3, b=9 }; // range 0:15
    enum e3 { min=-10, max=1000000 }; // range -1048576:1048575
    enum flag {x=1, y=2, z=4, e=8 }; // range 0:15
    The only sence to me is e1. dark has value 0 and light has value 1. For others I have no idea.
    What does that range mean anyway?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I second Salem on this one.


    enum e1 { dark, light }; // range 0:1

    dark = 0
    light = 1

    0 - 1


    enum e2 { a=3, b=9 }; // range 0:15

    a = 3 / 0011
    b = 9 / 1001^

    0000 - 1111
    0 - 15


    enum e3 { min=-10, max=1000000 }; // range -1048576:1048575

    max = 1000000 / F4240

    FFFFF (16) = 1048575 (10)


    enum flag {x=1, y=2, z=4, e=8 }; // range 0:15

    x = 1 / 0001
    y = 2 / 0010
    z = 4 / 0100
    e = 8 / 1000

    0000 - 1111
    0 - 15
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Understanding/Implementing Enumeration
    By Iconate in forum C Programming
    Replies: 15
    Last Post: 10-10-2008, 09:16 AM
  2. Enumeration Issues
    By cdn_bacon in forum C++ Programming
    Replies: 5
    Last Post: 05-03-2007, 02:26 PM
  3. Enumeration problem
    By baniakjr in forum C++ Programming
    Replies: 8
    Last Post: 11-11-2006, 02:32 PM
  4. Having trouble implementing enumeration.
    By RP319 in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2005, 07:03 PM
  5. enumeration
    By C-Struggler in forum C Programming
    Replies: 5
    Last Post: 03-13-2003, 09:36 AM