Thread: another mystifying C syntax issue - DEBUG macro - #define

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    44

    another mystifying C syntax issue - DEBUG macro - #define

    Simply unbelievable.
    Code:
    #define DEBUG
    #ifdef DEBUG
    #define dg(x) _tprintf(x)
    #else
    #define dg(x) do {} while (0)
    #endif
    


    dg ( (_T("parsed node %s %d"), wordwrk, z) );

    The above fails because the LAST _tprintf parameter is an INT. Swap the two and the syntax is then OK:

    dg ( (_T("parsed node %d %s"), z, wordwrk) );

    I'm all ears as to why this simply isn't a replacement of dg with _tprintf.



    Fortunately, I found another better use of macros for debugging:

    Code:
    #define NODEBUG2
    #ifdef DEBUG2
    #define D if(1)
    #else
    #define D if(0)
    #endif
    
    D _tprintf(_T(parsed node %s %d"), wordwrk, z);


    Last edited by jlewand; 02-12-2012 at 12:45 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How overload a define macro?
    By 6tr6tr in forum C++ Programming
    Replies: 19
    Last Post: 04-24-2008, 03:52 PM
  2. Is it possible to set type for define macro?
    By 6tr6tr in forum C++ Programming
    Replies: 5
    Last Post: 04-16-2008, 01:32 PM
  3. Newbie question about the define macro
    By lawina in forum C++ Programming
    Replies: 11
    Last Post: 05-18-2006, 06:47 PM
  4. Tricky #define macro...
    By willkoh in forum Windows Programming
    Replies: 4
    Last Post: 04-06-2005, 12:09 PM
  5. macro (#define) question
    By Darrok in forum C++ Programming
    Replies: 30
    Last Post: 12-20-2001, 05:01 PM