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