-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacro.c
More file actions
42 lines (36 loc) · 837 Bytes
/
macro.c
File metadata and controls
42 lines (36 loc) · 837 Bytes
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
#include <stdio.h>
#define str(s) #s
#define ASSIGN_PROPERTY_TO_PERSON(x) \
do { \
p.x = str(x); \
} while(0);
#define ASSIGN_PROPERTY_TO_FILE(x) \
do { \
file.x = dict[@str(x)];\
} while(0);
#define ASSIGN_PROPERTY_TO_FILE_WITHOUT_STR(x) \
do { \
file.x = dict[@#x]; \
} while(0);
#define ASSIGN_PROPERTY_TO_FILE_WITH_QUOTE(x) \
do { \
file.x = dict[@"x"]; \
} while(0);
#define ASSIGN_PROPERTY(x) file.x=dict[@#x]
#define sin(x) sin##x
struct Person
{
char *name;
char *gender;
};
int main(int argc, char *argv[])
{
struct Person p;
ASSIGN_PROPERTY_TO_PERSON(name);
ASSIGN_PROPERTY_TO_FILE(name);
ASSIGN_PROPERTY_TO_FILE_WITHOUT_STR(gender);
ASSIGN_PROPERTY_TO_FILE_WITH_QUOTE(gender);
ASSIGN_PROPERTY(gender);
int sin(God) = 2;
return 0;
}