programming/c.org
... ...
@@ -0,0 +1,39 @@
1
+<:PROPERTIES:
2
+#+TITLE: C Language
3
+#+AUTHOR:
4
+#+EMAIL:
5
+#+DATE: 2025-06-16 20:41:40
6
+#+OPTIONS: toc:nil todo:nil
7
+#+FILETAGS:
8
+#+STARTUP:
9
+:END:
10
+
11
+* Macros
12
+** Tricks
13
+
14
+*** Macro callback pattern for list of things
15
+
16
+#+begin_src c
17
+ #define LIST_OF_THINGS(DO) \
18
+ DO(ITEM_0) \
19
+ DO(ITEM_1) \
20
+ DO(ITEM_2) \
21
+ DO(ITEM_3) \
22
+ DO(ITEM_4) \
23
+ DO(ITEM_5) \
24
+ DO(ITEM_MAX)
25
+
26
+ typedef enum enumname {
27
+ #define DECL_ENUM(item) item,
28
+ LIST_OF_THINGS(DECL_ENUM)
29
+ #undef DECL_ENUM
30
+ } enumname_t;
31
+
32
+ const char* enumname_strings[] = {
33
+ #define DECL_S(it) #it,
34
+ LIST_OF_THINGS(DECL_S)
35
+ #undef DECL_S
36
+ };
37
+
38
+
39
+#+end_src