Last active
March 18, 2018 03:13
-
-
Save shengyu7697/a3c7d65dcfb1f1d8ceca87cf8e7dabc5 to your computer and use it in GitHub Desktop.
debug print
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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