Consider the following struct and function to create the struct:
#define MAX_ELEMS 1000
struct stuff {
double magic;
bool is_valid[MAX_ELEMS];
double values[MAX_ELEMS];
};
struct stuff make_stuff(double magic) {
return (struct stuff){
.magic = magic
};
}
In my case, I need stuff.magic
to be intialized to the given value, and the stuff.is_valid
array to be zero initialized, but I do not want to initialize stuff.values
(as they are guarded by stuff.is_valid
and initialized on-demand later).
Can I achieve this with designated initalizers?
I know I can achieve it without, but this is uglier and more error-prone (among other reasons, as I now need to explicitly zero stuff.is_valid
, perhaps with a memset).