-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmacro.cpp
More file actions
executable file
·82 lines (71 loc) · 1.8 KB
/
macro.cpp
File metadata and controls
executable file
·82 lines (71 loc) · 1.8 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* MacroExample.cpp
*
* Created on: Jan 4, 2012
* Author: behnam
*/
#include <iostream>
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
// define something for Windows (32-bit and 64-bit, this part is common)
#ifdef _WIN64
// define something for Windows (64-bit only)
#else
// define something for Windows (32-bit only)
#endif
#elif __APPLE__
#include <TargetConditionals.h>
#if TARGET_IPHONE_SIMULATOR
// iOS Simulator
#elif TARGET_OS_IPHONE
// iOS device
#elif TARGET_OS_MAC
// Other kinds of Mac OS
#else
#error "Unknown Apple platform"
#endif
#elif __linux__
// linux
#elif __unix__ // all unices not caught above
// Unix
#elif defined(_POSIX_VERSION)
// POSIX
#else
#error "Unknown compiler"
#endif
/*
1)First Example
*/
#define SOFTWARE "Software Version= "
#define VERSION 10
/*
2)in the CMakeLists.txt ADD_DEFINITIONS(-DLOGING=0) or
ADD_DEFINITIONS(-DLOGING=1)
*/
#if LOGING == 1
#define LOG(x) std::cout << x << " has happened" << std::endl
#else
#define LOG(x)
#endif
/*
3)Since the macro will replace the text where they used, they are like inline
functions and they will speed up code.
If you have multi line put a \
*/
#define ADD(a, b) \
{ (a + b); }
#define SWAP(a, b) \
{ \
(a) ^= (b); \
(b) ^= (a); \
(a) ^= (b); \
}
int main() {
std::cout << SOFTWARE << VERSION << std::endl;
int x, y;
x = 2;
y = 3;
ADD(x, y);
SWAP(x, y);
LOG("loading");
return 0;
}