debugging macros (again)

James Hu sirius at matt.ksu.ksu.edu
Thu Oct 4 10:14:01 AEST 1990


Hello.  I remember debugging macros were discussed sometime
last year, but I did not pay too close attention then.
Could someone advise me via email if the following header file
is ok?

/* debug.h:	My debugging macros */
#ifdef DEBUG
#  ifdef IN_MAIN_OBJECT

#  include <stdarg.h>

int debug_level = 0;

void BUG(int priority, char *fmt, ...)
{
    va_list ap;

    if (priority < 0) return;
    if ((-debug_level != priority) && (debug_level < priority)) return;
    va_start(ap, fmt);
    vfprintf(stderr, fmt, ap);
    va_end(ap);
}


#  else /* NOT MAIN */

    extern int debug_level;
    extern void BUG(int, char *,...);

#  endif /* MAIN */

#else /* NOT DEBUG */

#  ifdef IN_MAIN_OBJECT

     void BUG(int x, char *s,...) {}

#  else /* NOT MAIN */

     extern void BUG(int, char *,...);

#  endif /* MAIN */

#endif /* DEBUG */

/* end of debug.h */


My primary concern, of course, is if the compiler will optimize
the null function call down to doing nothing at all.
Thanks for any help.



More information about the Comp.lang.c mailing list