-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.h
27 lines (24 loc) · 819 Bytes
/
debug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef COMMON_H
#define COMMON_H
#include <stdio.h>
#include <sys/time.h>
// some handy macros for printing to stderr
#define E(fmt, ...) do { \
struct timeval tv; \
gettimeofday(&tv, NULL); \
fprintf(stderr, "[%06ld.%06ld] %s:%d ** ERROR ** " fmt, \
tv.tv_sec, tv.tv_usec, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
} while (0)
#ifdef DEBUG
#define D0(fmt, ...) do { fprintf(stderr, fmt, ##__VA_ARGS__); } while (0)
#define D(fmt, ...) do { \
struct timeval tv; \
gettimeofday(&tv, NULL); \
fprintf(stderr, "[%06ld.%06ld] %s:%d " fmt, \
tv.tv_sec, tv.tv_usec, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
} while (0)
#else
#define D0(fmt, ...) do{}while(0)
#define D(fmt, ...) do{}while(0)
#endif
#endif // COMMON_H