Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active January 24, 2019 12:15
Show Gist options
  • Save pervognsen/bca010dd64623e600b2dfc974968a4a3 to your computer and use it in GitHub Desktop.
Save pervognsen/bca010dd64623e600b2dfc974968a4a3 to your computer and use it in GitHub Desktop.
typedef struct {
void *data;
size_t num_items;
size_t max_items;
} array_t;
// ...
typedef struct {
union {
struct {
// Alias the fields of the untyped array with typed pointers and appropriate names.
char **files;
size_t num_files;
};
array_t files_array;
};
} file_list_t;
void file_list_init(file_list_t *file_list) {
array_init(&file_list->files_array, sizeof(char *));
}
void file_list_add(file_list_t *file_list, char *filename) {
array_add(&file_list->files_array, &filename, sizeof(char *));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment