2013-08-29

C: Log a message through a macro with the current function name and line number

// macro magic :D:D
 #define STRINGIFY(x) #x
 #define TOSTRING(x) STRINGIFY(x)
 #ifdef DEBUG
     #define LOG(x, ...) logzor( "NIHLEDTEST " __FILE__  ":"   \
          TOSTRING(__LINE__) " : " __FUNCTION__  "() ==> " x "n", __VA_ARGS__)
 #else
     #define LOG(x, ...)
 #endif
 
 #ifdef DEBUG
 static __inline void logzor(char *msg, ...)
 {
     va_list argptr;
     va_start(argptr, msg);
     vfprintf(stderr, msg, argptr);
     va_end(argptr);
 }
 #endif

No comments :

Post a Comment