u/Interesting_Buy_3969

How to zero-initialise non-specified values in an array at compile time?

Imagine a situation where you need to define whether a given character is vowel by accessing alphabet represented as an array of booleans (or integers). Like:

int is_vowel(const char c) { return arr[c]; }

So, we demand an array arr where at all vowels indeces the value is set to 1 or non-zero:

static const char arr[] = {
    ['a'] = 1, ['o'] = 1, ['e'] = 1, ['y'] = 1, ['u'] = 1};

The problem now is that the other values that we did not specify may be undefined (or if they may not, please correct me). Is there a way to force compiler to zero-initialise other values?
Does static const modifier guarantees anything about its value per standard in this case?

Of course i could simply make the array mutable and initialise it during runtime, but i would prefer do it at compile time. Maybe there's an attribute, or a language feature i have no clue about; so I wish to find out the most elegant and proper way to accomplish that.

reddit.com
u/Interesting_Buy_3969 — 6 hours ago