Derive-C
Loading...
Searching...
No Matches
readme.c
Go to the documentation of this file.
1#include <derive-c/prelude.h>
2
3#define CAPACITY 2048
4#define NAME alloc_2048
6
7#define ITEM char
8#define ALLOC alloc_2048
9#define NAME vec_char
11
12static void example_readme(DC_LOGGER* parent) {
13 DC_SCOPED(DC_LOGGER) log = DC_LOGGER_NEW(parent, "%s", __func__);
14
15 alloc_2048_buffer buf;
16 alloc_2048 alloc = alloc_2048_new(&buf, stdalloc_get_ref());
17 vec_char vec = vec_char_new(&alloc);
18
19 DC_LOG(log, DC_INFO, "pushing digits 1-9");
20 for (char x = 1; x <= 9; x++) {
21 vec_char_push(&vec, (char)('0' + x));
22 }
23
24 vec_char_iter_const iter = vec_char_get_iter_const(&vec);
25 char const* entry;
26 while ((entry = vec_char_iter_const_next(&iter))) {
27 DC_LOG(log, DC_INFO, "entry: %c", *entry);
28 }
29
30 vec_char_delete(&vec);
31}
32
33int main() {
35 root = NS(DC_LOGGER,
36 new_global)((NS(DC_LOGGER, global_config)){.stream = stdout, .ansi_colours = true},
37 (dc_log_id){"readme"});
38
39 example_readme(&root);
40 return 0;
41}
#define DC_LOGGER
Definition file.h:168
#define NS(pre, post)
Definition namespace.h:14
static void example_readme(DC_LOGGER *parent)
Definition readme.c:12
int main()
Definition readme.c:33
#define DC_SCOPED(type,...)
RAII in C. Call the destructor when the variable goes out of scope.
Definition scope.h:5
#define DC_LOGGER_NEW(...)
Definition prelude.h:21
#define DC_LOG(...)
Definition prelude.h:20
@ DC_INFO
Definition trait.h:8