Derive-C
Loading...
Searching...
No Matches
trait.c File Reference
#include <stdint.h>
#include <derive-c/prelude.h>

Go to the source code of this file.

Macros

#define Foo_REFLECT(F)

Functions

static void example_trait (DC_LOGGER *parent)
int main ()

Macro Definition Documentation

◆ Foo_REFLECT

#define Foo_REFLECT ( F)
Value:
F(uint32_t, bing) \
F(char, baz) \
F(char, zing)

Definition at line 5 of file trait.c.

5#define Foo_REFLECT(F) \
6 F(uint32_t, bing) \
7 F(char, baz) \
8 F(char, zing)

Function Documentation

◆ example_trait()

void example_trait ( DC_LOGGER * parent)
static

Definition at line 15 of file trait.c.

15 {
16 DC_SCOPED(DC_LOGGER) log = DC_LOGGER_NEW(parent, "%s", __func__);
17
18 Foo f = {.bing = 23, .baz = 'c', .zing = 'z'};
19 Foo g = {.bing = 23, .baz = 'c', .zing = 'z'};
20
21 DC_LOG(log, DC_INFO, "checking equality of f and g");
22 DC_ASSERT(Foo_eq(&f, &g));
23 DC_LOG(log, DC_INFO, "checking ordering of f and g");
24 DC_ASSERT(!Foo_gt(&f, &g) && !Foo_lt(&f, &g));
25
26 DC_LOG(log, DC_INFO, "cloning f to z and incrementing bing");
27 Foo z = Foo_clone(&f);
28 z.bing += 10;
29 DC_LOG(log, DC_INFO, "checking z > f");
30 DC_ASSERT(Foo_gt(&z, &f));
31}
#define DC_LOGGER
Definition file.h:168
#define DC_ASSERT(expr,...)
Definition panic.h:37
#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

◆ main()

int main ( )

Definition at line 33 of file trait.c.

33 {
35 root = NS(DC_LOGGER,
36 new_global)((NS(DC_LOGGER, global_config)){.stream = stdout, .ansi_colours = true},
37 (dc_log_id){"trait"});
38
39 example_trait(&root);
40 return 0;
41}
#define NS(pre, post)
Definition namespace.h:14
static void example_trait(DC_LOGGER *parent)
Definition trait.c:15