pre compiler #if 0?

This is a discussion on pre compiler #if 0? within the C Programming forums, part of the General Programming Boards category; I'm editing some existing code, and in the code, there are several statements: Code: #if 0 blah blha blha blah ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    245

    pre compiler #if 0?

    I'm editing some existing code, and in the code, there are several statements:

    Code:
    #if 0
       blah blha
       blha blah
    #endif
    what does #if 0 do? It seems to me that it just ignores the code in between the if block??

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    Quote Originally Posted by dayalsoap View Post
    It seems to me that it just ignores the code in between the if block??
    Exactly that.
    Devoted my life to programming...

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,246
    It's a way of disabling code in a way that is easily switchable -- you flip the switch by changing the 0 to a 1.

    Normally this kind of thing is temporary. It might surround a piece of experimental code, or code that isn't quite ready for prime time yet. Using a constant 0 isn't as useful as a preprocessor macro, though:

    Code:
    #if ENABLE_SOME_FEATURE
    ...
    #endif
    This way the feature can be controlled from a header file or even a compiler switch (by defining the ENABLE_SOME_FEATURE symbol you can control the presence of the bit of code at compile time)
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  2. New compiler - Weird errors -,-.
    By Blackroot in forum C++ Programming
    Replies: 8
    Last Post: 08-27-2006, 07:23 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 05:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 10:28 AM

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