Notices
Results 1 to 2 of 2

Thread: Is using non-type defined enumerated list essentially the same as hash defining integers?

  1. #1 Is using non-type defined enumerated list essentially the same as hash defining integers? 
    Forum Ph.D.
    Join Date
    Jan 2013
    Posts
    908
    Does using non-type defined enumerated list generate the same machine code as hash defining integers?

    Code:
    enum foodID{   
        BURGER = 0,
        DRINK,
        FRIES,
        WEDGE_POTATO,
        POPCORN,
    
    
        FOOD_MAX
    };
    Code:
    #define BURGER 0
    #define DRINK 1
    #define FRIES 2
    #define WEDGE_POTATO 3
    #define POPCORN 4
    #define FOOD_MAX 5
    Well, i know that at this point, there's a difference, since the enum type can be used to store data
    Code:
    foodID createdFoodIDVariable = POPCORN;
    But if i remove the type i assigned this enum to............

    Code:
    enum { 
        BURGER = 0,
        DRINK,
        FRIES,
        WEDGE_POTATO,
        POPCORN,
    
    
        FOOD_MAX
    };
    Now i can't declare any variables with this data type, since there isn't any data type assigned to this enumerated list.
    Please correct me if i'm wrong..

    What difference does it have compared to #define -ing each of those data?
    1. Computer cycles (amount of operations require to assign/get each enum/defined
    2. Does enum provide any other benefit other than requiring assignment of numbers to each of them, like = 1, = 2, = 3,...
    3. Does the ability of enum to scope the variables here make the program need more processing logic gate operations than #define -ing each piece of data?
    4. I understand most of these stuff probably make hardly/no difference, but i'm trying to discuss these micro-level optimizations to understand more on how most compilers work...


    Thanks for the replies!


    Quote Originally Posted by jocular View Post
    If thy right nipple offend thee, pluck it off! Goes for the other, too!
    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    Posts
    3,440
    As far as I can remember, the two are exactly the same in C/C++. The type name doesn't even matter. You can say foodID x = 10 or int y = POPCORN. It's all just syntactic sugar to make writing and reading programs easier. (Outside of C/C++, other languages that have enums tend to do more with them.)


    Reply With Quote  
     

Similar Threads

  1. A new hypothesis re-defined quantum research!
    By Mixter in forum Personal Theories & Alternative Ideas
    Replies: 4
    Last Post: August 3rd, 2012, 11:07 AM
  2. Applying sequences to non-integers
    By brody in forum Mathematics
    Replies: 2
    Last Post: January 1st, 2012, 05:29 PM
  3. Mathematically defined units
    By helix in forum Physics
    Replies: 2
    Last Post: October 20th, 2011, 11:29 AM
  4. Is |0| (mod of zero) invalid (i.e. not defined)?
    By Sudhamsu in forum Mathematics
    Replies: 2
    Last Post: February 14th, 2009, 12:45 PM
  5. integers
    By parag in forum Mathematics
    Replies: 14
    Last Post: August 12th, 2008, 02:50 PM
Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •