Thread: #define and #undef

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

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, 01: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, 10:56 AM
  4. Replies: 1
    Last Post: 03-17-2005, 08:53 AM
  5. noob problem with a number generator
    By Amoreldor in forum C Programming
    Replies: 14
    Last Post: 03-10-2005, 10:39 AM