Skip to content

Instantly share code, notes, and snippets.

@shengyu7697
Last active March 18, 2018 03:13
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 shengyu7697/a3c7d65dcfb1f1d8ceca87cf8e7dabc5 to your computer and use it in GitHub Desktop.
Save shengyu7697/a3c7d65dcfb1f1d8ceca87cf8e7dabc5 to your computer and use it in GitHub Desktop.
debug print
#define DEBUG 4
#if defined(DEBUG)
#if DEBUG >= 4 // filename:function:line
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, "[DEBUG] %s:%s():%d " fmt, \
__FILE__, __func__, __LINE__, ##__VA_ARGS__)
#elif DEBUG >= 3 // filename:function
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, "[DEBUG] %s:%s() " fmt, \
__FILE__, __func__, ##__VA_ARGS__)
#elif DEBUG >= 2 // filename:line
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, "[DEBUG] %s:%d " fmt, \
__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#elif DEBUG >= 1 // function:line
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, "[DEBUG] %s():%d " fmt, \
__func__, __LINE__, ##__VA_ARGS__)
#endif
#else
#define DEBUG_PRINT(fmt, ...) // Don't do anything in release builds
#endif
DEBUG_PRINT("Debugging is enabled.\n");
DEBUG_PRINT("Debug level: %d", (int) DEBUG);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment