Difference between Enums and #define preprocessor

This is a discussion on Difference between Enums and #define preprocessor within the C Programming forums, part of the General Programming Boards category; Hi Can any one tell me the difference between preprocessor macros like #define and enum; If i want to define ...

  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 05:54 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    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, 09: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

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