4 ms·
I thought the same thing. Why is calloc not widely used? That said, when initializing structs `= { 0 }` can be used to set all members 0. And at least in more
by jonhohle 3y ago
I thought the same thing. Why is calloc not widely used?
That said, when initializing structs `= { 0 }` can be used to set all members 0. And at least in more recent compilers you can used the designated initializer with dynamic allocation by casting:
Foo* f = malloc(sizeof(Foo));
*f = (Foo) { .bar = 1, .baz = “car” };
If a member is missed, it will be set to zero (the value for uninitialized static storage).