OSDN Git Service

Regular updates
[twpd/master.git] / c_preprocessor.md
1 ---
2 title: C Preprocessor
3 category: C-like
4 ---
5
6 ### Compiling
7
8     $ cpp -P file > outfile
9
10 ### Includes
11
12     #include "file"
13
14 ### Defines
15
16     #define FOO
17     #define FOO "hello"
18
19     #undef FOO
20
21 ### If
22
23     #ifdef DEBUG
24       console.log('hi');
25     #elif defined VERBOSE
26       ...
27     #else
28       ...
29     #endif
30
31 ### Error
32
33     #if VERSION == 2.0
34       #error Unsupported
35       #warning Not really supported
36     #endif
37
38 ### Macro
39
40     #define DEG(x) ((x) * 57.29)
41
42 ### Token concat
43
44     #define DST(name) name##_s name##_t
45     DST(object);   #=> "object_s object_t;"
46
47 ### file and line
48
49     #define LOG(msg) console.log(__FILE__, __LINE__, msg)
50     #=> console.log("file.txt", 3, "hey")