Why do the enum values this way??

This is a discussion on Why do the enum values this way?? within the C Programming forums, part of the General Programming Boards category; Code: enum tx_op { P_TX = 1, PU_TX = 1 + 1, RT_TX = 1 + 2, GET_TX = 1 ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    245

    Why do the enum values this way??

    Code:
    enum tx_op {
            P_TX = 1,
            PU_TX = 1 + 1,
            RT_TX = 1 + 2,
            GET_TX = 1 + 3,
            PUT_TX = 1 + 4,
    };
    What's the purpose of the 1+1, 1+2, etc.. why not just do 2,3,4......??

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,415
    Yeah, it looks like cruft. It could have been written as:
    Code:
    enum tx_op {
        P_TX = 1,
        PU_TX,
        RT_TX,
        GET_TX,
        PUT_TX,
    };
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. enum values not working in #define?
    By MattJ812 in forum C++ Programming
    Replies: 22
    Last Post: 01-15-2011, 05:36 AM
  2. Assigning enum types to enum types?
    By see the big C in forum C Programming
    Replies: 10
    Last Post: 12-21-2010, 01:32 AM
  3. Printing values from Enum
    By Raskalnikov in forum C Programming
    Replies: 8
    Last Post: 02-16-2009, 09:28 PM
  4. How to pass enum values
    By Bargi in forum C++ Programming
    Replies: 1
    Last Post: 09-29-2007, 02:55 AM
  5. different values in while using enum?
    By blackgold>> in forum C++ Programming
    Replies: 1
    Last Post: 04-26-2004, 03:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21