4 ms·
Note that something like this is actually part of C99 (but not of C++ - the C++ grammar was apparently too tortured to support this): struct example_t {
by JoachimSchipper 12y ago
Note that something like this is actually part of C99 (but not of C++ - the C++ grammar was apparently too tortured to support this):
struct example_t {
int foo, bar, baz;
} example = {
.foo = 1,
.bar = 42,
};
/* unnamed members are implicitly set to 0 / NULL */
assert(example.baz == 0);
combined with compound literals, you can do stuff like
example = (struct example_t){
.foo = 2,
.baz = 1
};
assert(example_cmp(&example,
&(struct example_t){ .foo = 2 }) == 0);
It's one of C99's neater features, I think. I can imagine C++ programmers liking something like iod.