Last active
May 28, 2016 17:55
-
-
Save alivesay/2e8fdd95759b5470fd79afe57ddca36d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foo_types_header.h: | |
typedef enum { | |
FOO_TYPE_BAR = 0, | |
_FOO_TYPE_COUNT | |
} foo_type_t; | |
foo_bar_header.h: | |
typedef struct { | |
foo_type_t type; | |
int* x; | |
} foo_bar_t; | |
foo_bar_t* foo_bar_create(void); | |
foo_bar_t* foo_bar_init(foo_bar_t *const bar); | |
void foo_bar_destroy(foo_bar_t *const bar); | |
void foo_bar_free(foo_bar_t** bar); | |
foo_bar_header.c: | |
foo_bar_t* foo_bar_create(void) { | |
foo_bar_t* bar = calloc(sizeof(foo_bar_t)); | |
foo_bar_init(bar); | |
return bar; | |
} | |
foo_bar_t* foo_bar_init(foo_bar_t *const bar) { | |
bar->type = FOO_TYPE_BAR; | |
bar->x = malloc(sizeof(*bar->x)); | |
} | |
void foo_bar_destroy(foo_bar_t *const bar) { | |
free(bar->x); | |
} | |
void foo_bar_free(foo_bar_t** bar) { | |
foo_bar_destroy(*bar); | |
free(*bar); | |
*bar = NULL; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment