Thu, 30 Dec 2010 00:44:25 +0000
add NELEMS macro to utils.h
philpem@88 | 1 | #ifndef _UTILS_H |
philpem@88 | 2 | #define _UTILS_H |
philpem@71 | 3 | |
philpem@71 | 4 | #ifndef NDEBUG |
philpem@71 | 5 | /// Log a message to stderr |
philpem@71 | 6 | # define LOG(x, ...) do { fprintf(stderr, "%s:%d:%s(): " x "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); } while (0) |
philpem@71 | 7 | /// Log a message to stderr if 'cond' is true |
philpem@71 | 8 | # define LOG_IF(cond, x, ...) do { if (cond) fprintf(stderr, "%s:%d:%s(): " x "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); } while (0) |
philpem@71 | 9 | #else |
philpem@71 | 10 | #define LOG(x, ...) |
philpem@71 | 11 | #define LOG_IF(cond, x, ...) |
philpem@71 | 12 | #endif |
philpem@71 | 13 | |
philpem@88 | 14 | /// Get the number of elements in an array |
philpem@88 | 15 | #define NELEMS(x) (sizeof(x)/sizeof(x[0])) |
philpem@88 | 16 | |
philpem@71 | 17 | #endif // _H_UTILS |