2 ms·
> this function needs to fill in the zeroes with default values anyway Wait - no. What's wrong with #define BLA_INIT_DEFAULT { .a = 23, .hello = "Hello Wo
by pantalaimon 4y ago
> this function needs to fill in the zeroes with default values anyway
Wait - no. What's wrong with
#define BLA_INIT_DEFAULT { .a = 23, .hello = "Hello World!", }
struct bla_t blub = BLA_INIT_DEFAULT;
blub.a = 42;
That's what your proposal would do under the hood anyway, just more explicit.
- flohofwoe 4y agoYou can even change that to: #define BLA_DEFAULTS .a = 23, .hello = "Hello World!" struct bla_t blub = { BLA_DEFAULTS, .a = 42, }; ...because C99 allows designated initializers to show up multiple times, but that's all a bit too much macro magic for my taste, I'd really prefer the defaults in the struct declaration.