Created
September 4, 2011 04:19
-
-
Save jlintz/1192247 to your computer and use it in GitHub Desktop.
Useful C debug macro
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
#ifdef DEBUG | |
#define _DEBUG(fmt, args...) printf("%s:%s:%d: "fmt, __FILE__, __FUNCTION__, __LINE__, args) | |
#else | |
#define _DEBUG(fmt, args...) | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should put {} after the macro defined in the else clause
e.g #define _DEBUG(fmt, args...) {} so it wont mess with "if" statements
I needed to be able to turn debug on and off from a conf file and also #define it out at compile time sometimes, so i use this:
//#define DO_DEBUG
int debug; // set from conf file at runtime
#ifdef DO_DEBUG
#define debug_print(fmt, ...) do { if(debug == 1){plog(__FILE__, ___FUNCTION__, __LINE__, ((fmt)), ##__VA_ARGS__);} } while (0)
#else
#define debug_print(fmt, ...){}
#endif
plog is my logging function