Thread: Difference between Enums and #define preprocessor

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    13

    Difference between Enums and #define preprocessor

    Hi
    Can any one tell me the difference between preprocessor macros like
    #define and enum;
    If i want to define MAX_LIMIT=100 as preprocessor macro as
    Code:
    #define MAX_LIMIT 100;
    or if i define
    Code:
    enum {MAX_LIMIT=100};
    then what is the basic difference?
    Last edited by kollurisrinu; 12-05-2007 at 06:54 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    An enum can be type checked.
    An enum will print the symbolic value if you try to examine it in the debugger.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    That's just a silly use of enum. I hope you understand that. In this case, a const int would be better.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code::Blocks doesn't like my enums and typedefs
    By muehl in forum C++ Programming
    Replies: 19
    Last Post: 02-12-2009, 10:48 AM
  2. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM