-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
30 lines (27 loc) · 891 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "./src/u_ptr.h"
int main(void)
{
int i_val = 123123123;
double d_val = 123123123.123;
char c_val = 'a';
u_ptr* i_ptr = u_ptr_init(&i_val, sizeof(i_val), INT);
u_ptr* d_ptr = u_ptr_init(&d_val, sizeof(d_val), DOUBLE);
u_ptr* c_ptr = u_ptr_init(&c_val, sizeof(c_val), CHAR);
// Print the data from the unique_ptr with automatic type detection from u_ptr_init
u_ptr_print(i_ptr);
u_ptr_print(d_ptr);
u_ptr_print(c_ptr);
// Reset the unique_ptr to NULL ready for re assignment with u_ptr_init
u_ptr_reset(i_ptr);
u_ptr_reset(d_ptr);
u_ptr_reset(c_ptr);
// Will not print anything as data is NULL and has no size
u_ptr_print(i_ptr);
u_ptr_print(d_ptr);
u_ptr_print(c_ptr);
// ToDo: Automatically free memory when unique_ptr goes out of scope
free(i_ptr);
free(d_ptr);
free(c_ptr);
return 0;
}