For example, if I were to create a hierarchical static const struct
like this in a header (.h
) file:
static const struct {
struct {
char STATIC /* = 0 */;
char DYNAMIC /* = 1 */;
} ALLOCATION;
struct {
char TABLE /* = 0 */;
char LIST /* = 1 */;
char TREE /* = 2 */;
} STRUCTURE;
} FOO_STRATEGY = { {0, 1}, {0, 1, 2} };
foo_t *foo_create(char allocation_strategy, char structure_type);
Which would then be used something like this:
foo_t *foo = foo_create(FOO_STRATEGY.ALLOCATION.STATIC, FOO_STRATEGY.STRUCTURE.TREE);
I guess I have a two-part question:
- Does this work as one would expect?
- Why don't other people do this?