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
5
#include <
derive-c/alloc/hybridstatic/template.h
>
6
7
#define ITEM char
8
#define ALLOC alloc_2048
9
#define NAME vec_char
10
#include <
derive-c/container/vector/dynamic/template.h
>
11
12
static
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
33
int
main
() {
34
DC_SCOPED
(
DC_LOGGER
)
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
}
template.h
template.h
DC_LOGGER
#define DC_LOGGER
Definition
file.h:168
NS
#define NS(pre, post)
Definition
namespace.h:14
prelude.h
example_readme
static void example_readme(DC_LOGGER *parent)
Definition
readme.c:12
main
int main()
Definition
readme.c:33
DC_SCOPED
#define DC_SCOPED(type,...)
RAII in C. Call the destructor when the variable goes out of scope.
Definition
scope.h:5
dc_log_id
Definition
trait.h:39
DC_LOGGER_NEW
#define DC_LOGGER_NEW(...)
Definition
prelude.h:21
DC_LOG
#define DC_LOG(...)
Definition
prelude.h:20
DC_INFO
@ DC_INFO
Definition
trait.h:8
examples
complex
readme.c
Generated by
1.16.0