Derive-C
Loading...
Searching...
No Matches
bitset.c
Go to the documentation of this file.
1
4
5#include <derive-c/prelude.h>
6
7#define EXCLUSIVE_END_INDEX 128
8#define NAME bitset
10
11static void example_basic(DC_LOGGER* parent) {
12 DC_SCOPED(DC_LOGGER) log = DC_LOGGER_NEW(parent, "%s", __func__);
13 DC_SCOPED(bitset) bs = bitset_new();
14
15 DC_LOG(log, DC_INFO, "setting bits at index 0 and 5");
16 bitset_set(&bs, 0, true);
17 bitset_set(&bs, 5, true);
18
19 DC_LOG(log, DC_INFO, "bitset: %s", DC_DEBUG(bitset_debug, &bs));
20
21 for (bitset_index_t i = 0; i < 128; i++) {
22 if (bitset_get(&bs, i)) {
23 DC_LOG(log, DC_INFO, "bit at index %u is set", i);
24 }
25 }
26
27 DC_FOR_CONST(bitset, &bs, iter, index) { DC_LOG(log, DC_INFO, "iterated index: %u", index); }
28}
29
30int main() {
32 root = NS(DC_LOGGER,
33 new_global)((NS(DC_LOGGER, global_config)){.stream = stdout, .ansi_colours = true},
34 (dc_log_id){"bitset"});
35
36 example_basic(&root);
37 return 0;
38}
static void example_basic(DC_LOGGER *parent)
Definition bitset.c:11
int main()
Definition bitset.c:30
#define DC_DEBUG(DEBUG_FN, DEBUG_PTR)
Definition dump.h:92
#define DC_LOGGER
Definition file.h:168
#define DC_FOR_CONST(TYPE, INSTANCE, ITER, ITEM)
Definition for.h:14
#define NS(pre, post)
Definition namespace.h:14
#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