-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreprocessors.cpp
More file actions
63 lines (49 loc) · 1.28 KB
/
Preprocessors.cpp
File metadata and controls
63 lines (49 loc) · 1.28 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
#include <iostream>
//preprocessors are executed during runtime, but when compiled
#define PI (3.14159)
//my program will replace PI with 3.14159
//there is no variable in memory
//can use with strings too
#define SHM_NAME "mySharedMemory"
//arrays
#define MAX_SIZE (128)
//functions - not reccomended
#define square(a) a*a
//undefine
#define undefinedVar
#undef undefinedVar
//IF statements
#define TRIGGER
//For 2 header files that include eachother. Basicly says Include this ONCE so we dont loop "I include you & you include me"
//#pragma once
int main(){
std::cout << PI << std::endl;
std::cout << SHM_NAME << std::endl;
/* int array1[MAX_SIZE];
for(int i=0; i < MAX_SIZE; i++){
array1[i] = i;
std::cout << array1[i] << std::endl;
} */
int i = 5;
std::cout << square(i) << std::endl;
//CAN NOT DO i++ because it replaces a string
std::cout << square(i++) << std::endl;
//can do
//#undef undefinedVar
//IF statements
#ifdef TRIGGER
std::cout << "Trigger is defined \n";
#endif
//IF not defined
#ifndef PIG
#define PIG "oink oink"
#endif
std::cout << PIG << std::endl;
return 0;
//nested if - this example is if LINUX & WINDOWS both are true
#ifdef WIN64
#ifdef LINUX
#error
#endif
#endif
}