Derive-C
Loading...
Searching...
No Matches
option.c
Go to the documentation of this file.
1
4
5#include <assert.h>
6#include <stdlib.h>
7#include <string.h>
8
10 int x;
11 double y;
13};
14
15void complex_data_delete(struct complex_data* self) { free(self->description); }
16
17#define T struct complex_data
18#define T_DELETE complex_data_delete
19#define SELF complex_data_option
21
23 complex_data_option opt = complex_data_option_empty();
24 assert(!complex_data_option_is_present(&opt));
25
26 // when accessing a value, you get a pointer. Not present = NULL
27 assert(!complex_data_option_get(&opt));
28 assert(!complex_data_option_get_const(&opt));
29
30 bool was_present_1 = complex_data_option_replace(
31 &opt, (struct complex_data){.x = 42, .y = 3.14, .description = strdup("A complex data")});
32 assert(!was_present_1);
33
34 assert(complex_data_option_is_present(&opt));
35 assert(complex_data_option_get(&opt));
36
37 bool was_present_2 = complex_data_option_replace(
38 &opt,
39 (struct complex_data){.x = 100, .y = 2.71, .description = strdup("Another complex data")});
40 assert(was_present_2);
41
42 complex_data_option_delete(&opt);
43}
44
45int main() { option_example(); }
void complex_data_delete(struct complex_data *self)
Definition option.c:15
void option_example()
Definition option.c:22
int main()
Definition option.c:45
char * description
Definition option.c:12
double y
Definition option.c:11