Skip to content

Instantly share code, notes, and snippets.

@tomaslibal
Created July 12, 2015 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomaslibal/3a9b04a97ae3d1b2373f to your computer and use it in GitHub Desktop.
Save tomaslibal/3a9b04a97ae3d1b2373f to your computer and use it in GitHub Desktop.
DEBUG PRINT in C as a macro
// From the TRE package
#ifdef TRE_DEBUG
#include <stdio.h>
#define DPRINT(msg) do {printf msg; fflush(stdout);} while(/*CONSTCOND*/(void)0,0)
#else /* !TRE_DEBUG */
#define DPRINT(msg) do { } while(/*CONSTCOND*/(void)0,0)
#endif /* !TRE_DEBUG */
// Updated for my use
#define APP_DEBUG 1
#ifdef APP_DEBUG
#define DEBUGPRINT(...) fprintf(stdout, __VA_ARGS__)
#define PRNTSTR(val,name) \
printf("%s = %s\n", name, val);
#else /* !APP_DEBUG */
#define DEBUGPRINT(...)
#define PRNTSTR(...)
#endif /* !APP_DEBUG */
// Inspiration from http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=%2Fcom.ibm.vacpp7a.doc%2Flanguage%2Fref%2Fclrc09cpxmac.htm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment