#define and #undef

This is a discussion on #define and #undef within the C Programming forums, part of the General Programming Boards category; I have following code in .h file #define ABC 1 #define PQR 1 #if (ABC == 1) #define PQR 0 ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    175

    #define and #undef

    I have following code in .h file


    #define ABC 1

    #define PQR 1

    #if (ABC == 1)
    #define PQR 0
    #endif

    Is it ok to say so or do I need to say undef PQR?

    What is difference between two?

    Apart from this, Any link for good pre-processor tutorails is appreciated...

    Thanks,

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You never need to #undef. You can, but redefinition is allowed (as far as macros are concerned anyway).
    Code:
    #define FOO 1
    #define FOO 0
    Perfectly legal.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    Well if you don't use #undef, you'll probably get "macro redeclared" errors.

    Like goto's, you can create a huge mess very quickly if you keep definining and undefining things, so it's use needs to be pretty exceptional.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Animated GIF Encoding Library
    By Tonto in forum C++ Programming
    Replies: 3
    Last Post: 01-08-2008, 12:57 PM
  2. Help making Program Better/More Effecient
    By toonlover in forum C++ Programming
    Replies: 14
    Last Post: 04-29-2006, 11:40 PM
  3. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 09:56 AM
  4. Replies: 1
    Last Post: 03-17-2005, 07:53 AM
  5. noob problem with a number generator
    By Amoreldor in forum C Programming
    Replies: 14
    Last Post: 03-10-2005, 09:39 AM

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