@@ -11,5 +11,54 @@ Reflection implementation is based on [DWARF](https://en.wikipedia.org/wiki/DWAR
11
11
12
12
** Features** :
13
13
14
- * 'Deep' functionality for printing, copying, comparing, and freeing memory of complex data structures: [ demo link] ( /doc/demo/README.md#how-to-demo ) .
14
+ * Reflection for all native C types.
15
+ * 'Deep' functionality for printing, copying, comparing, and freeing memory of complex data structures.
15
16
* Supported on Ubuntu, macOS, Windows (msys2) with gcc or clang
17
+
18
+ [ ** Example** ] ( /examples/c_app_simplest/ ) :
19
+
20
+ ``` c
21
+ #include < stdio.h> // printf
22
+ #include < stdlib.h> // free
23
+ #include < math.h> // M_PI, M_E
24
+ #include " metac/reflect.h"
25
+
26
+ struct test {
27
+ int y;
28
+ char c;
29
+ double pi;
30
+ double e;
31
+ short _uninitialized_field;
32
+ };
33
+
34
+ int main (){
35
+ // we need to use this construction to wrap variable declaration
36
+ // to get its type information
37
+ WITH_METAC_DECLLOC (decl_location,
38
+ struct test t = {
39
+ .y = -10,
40
+ .c = 'a',
41
+ .pi = M_PI,
42
+ .e = M_E,
43
+ };
44
+ )
45
+ metac_value_t * p_val = METAC_VALUE_FROM_DECLLOC(decl_location, t);
46
+
47
+ char * s;
48
+ s = metac_entry_cdecl(metac_value_entry(p_val));
49
+ // next will output "struct test t = "
50
+ printf ("%s = ", s);
51
+ free(s);
52
+
53
+ s = metac_value_string(p_val);
54
+ // next will output "{.y = -10, .c = 'a', .pi = 3.141593, .e = 2.718282, ._uninitialized_field = 0,};\n"
55
+ printf ("%s;\n", s);
56
+ free(s);
57
+
58
+ metac_value_delete (p_val);
59
+
60
+ return 0;
61
+ }
62
+ ```
63
+
64
+ To get more details please refer to the [ How to] ( /doc/demo/README.md#how-to-demo ) document.
0 commit comments