-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompilerAssertDebugMacro.cpp
More file actions
37 lines (29 loc) · 1.05 KB
/
compilerAssertDebugMacro.cpp
File metadata and controls
37 lines (29 loc) · 1.05 KB
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
28
29
30
31
32
33
34
35
36
37
//ASSERT preprocessor directive helps with debugging using boolean values
//mulitple statements can be included in macro function using backslash \ at end of line
//ASSERT function can be controlled by a DEBUG macro
//#define DEBUG allows debugging to be turned on/off by changing value of DEBUG
#define DEBUG 1
//macro if-elif statement to define ASSERT function according to control value
//when debugging is set to on, ASSERT function is defined
#if (DEBUG==1)
#define ASSERT(expr) \
std::cout << #expr << "..." << num; \
if (expr!=true) { \
std::cout << " Failed in file: " << __FILE__ ; \
std::cout << std::endl << "at line" << __LINE__ << std::endl; \
std::cout << "\nDate: " << __DATE__ << "\nTime: " << __TIME__; \
} \
else { \
std::cout << " Passed" << std::endl; \
}
//when debugging is set to off, ASSERT function is not defined
#elif (DEBUG==0)
#define ASSERT(result) \
std::cout << "Result is " << num << std::endl;
#endif
#include <iostream>
int main() {
int num = 9; ASSERT(num<10);
num++; ASSERT(num<10);
return 0;
}