Thread: macro directive question

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    222

    macro directive question

    For the following directive snippet, would the contents of the if directive executive only when DBG is equal to a non-zero value?

    Code:
    #if DBG
    #define SHOULD(b)       { if (!(b)) DEBUGMESSAGE( ("FAILURE CONDITION ENCOUNTERED") ); }
    #else
    #define SHOULD(b)       /* empty value */
    #endif

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    You could always try it and find out, but yes, that's how it works.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    what you are looking for is assert() in <cassert>.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by cyberfish View Post
    what you are looking for is assert() in <cassert>.
    Although assert() only works in Debug mode (i.e. if NDEBUG isn't defined); so if that's what you want, go with assert(), otherwise creating your own is fine.
    assert() also ends the program, which might not always be what you want.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    By defining a macro to nothing, the entire macro will be reduces to nothing after the preprocessor processes it, so nothing is left afterwards.
    So you could say that it will only execute in debug.
    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. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. design question: opinion
    By ggs in forum C Programming
    Replies: 2
    Last Post: 01-29-2003, 11:59 AM
  5. macro (#define) question
    By Darrok in forum C++ Programming
    Replies: 30
    Last Post: 12-20-2001, 05:01 PM