#define DEBUG... (using printf for debugging)
    Wayne Hathaway 
    wayne at ultra.com
       
    Sat May  5 07:28:15 AEST 1990
    
    
  
travis at cs.columbia.edu (Travis Lee Winfrey) suggests:
  # ifdef DEBUG
  #       define dprintf(dlevel,printfargs)  if (dlevel <= DEBUG ) \
                                                  printf printfargs  
  # else /* DEBUG */
  #       define dprintf(a,b)
  # endif /* DEBUG */
A good idea, and one which I also use (slightly more generalized, of
course; I just can't resist getting too damn fancy for my own good!).
I do have one nit, though:  I would suggest defining "dprintf" as:
    define dprintf(dlevel,printfargs)  if (dlevel > DEBUG) ; \
                                       else printf printfargs
Why?  Consider the following:
        if ( <some_strange_situation> )
            dprintf(1, ("oh no! just had some strange situation\n"));
        else
            <regular_processing>;
You see, I just HATE programs that stop working when you turn on the
DEBUG flag!  :-)
wayne
  Wayne Hathaway            
  Ultra Network Technologies     domain: wayne at Ultra.COM
  101 Daggett Drive            Internet: ultra!wayne at Ames.ARC.NASA.GOV
  San Jose, CA 95134               uucp: ...!ames!ultra!wayne
  408-922-0100
    
    
More information about the Comp.lang.c
mailing list