Question is in the code below, asking whether using value initialization syntax as shown would mean zero-initialized or uninitialized for the individual bit-field members:
struct S { // S is POD
int a : 3;
int b : 1;
};
S s1;
S s2{};
s1.a; // uninitialized (ok, we understand this)
s1.b; // "
s2.a; // zero or junk?
s2.b; // "
Here is a refresher for bit-fields: https://en.cppreference.com/w/cpp/language/bit_field
Creating zeroing constructors for structs with many bit fields is typically done with an ugly memset in legacy code since repeating the name of each bitfield member with value-init syntax in constructor initializer list yields unmanageable code. This is done even if the struct is a POD for good measure. Would like to eliminate that if possible in C++11 (default-member initialization syntax is not available for bit fields until C++20 unfortunately). Does C++11 guarantee zero-initialization for this with {}-init syntax?