Differences between Enumeration and Macro are:

    • Enumeration is a type of integer.
    • Macros can be of any type. Macros can even be any code block containing statements, loops, function calls etc.
    • Syntax/Example of Enumeration:
        element1, /*Default 0*/
        element3 = 5,
      #define WORD unsigned short
    • Macros are expanded by the preprocessor before compilation takes place. Compiler will refer error messages in expanded macro to the line where the macro has been called.
      Line:1:#define set_userid(x)\
      Line:2:current_user = x \
      Line:3:next_user = x + 1; 
      Line:4:int main (int argc, char *argv[])
      Line:6:  int user = 10;
      Line:7:  set_userid(user);
      main.c(7):error C2146: syntax error : missing ';' 
                before identifier 'next_user'
      Line 2 has the original compilation error

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

NULL pointer, enum type, macro, macro vs constant, enum vs macro, macro vs typedef, debug builds, debug macros, compiler macro for C++,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan