-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.cpp
43 lines (35 loc) · 1.16 KB
/
macros.cpp
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
38
39
40
41
42
43
// https://www.youtube.com/watch?v=j3mYki1SrKE&list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb&index=55
#include <iostream>
#define LOG(x) std::cout << x << std::endl
// before compiling, the preprocesser:
// replaces all instances of LOG with std::cout << x << std::endl
// replaces all instances of x inside LOG with the argument passed in
#define STR_HELLO "Hello!"
// this is horrendous never do something like this
// this is just an example to show how macros replace text
#if DEBUG == 1
#define EFFICIENT_LOG(x) std::cout << x << std::endl
#define ASSERT(x) \
if (!(x)) \
__debugbreak();
#else
#define EFFICIENT_LOG(x)
#define ASSERT(x)
#endif
// g++ -D DEBUG=1 macros.cpp -o macros
// this will define DEBUG as 1 before compiling
#define OPENGL
int main()
{
LOG("Hello World!"); // this is the same as std::cout << "Hello World!" << std::endl;
LOG(STR_HELLO); // this is the same as std::cout << "Hello!" << std::endl;
EFFICIENT_LOG("Debug message...");
// macros can be anywhere in the code
#ifdef OPENGL
LOG("Do OpenGL stuff...");
#elif VULKAN
LOG("Do Vulkan stuff...");
#else
LOG("Sorry, no graphics API for you :(");
#endif
}