3 ms·
> Which requires you to know that you can declare a type & an instance of that type in a single statement struct A { int i; }; const struc
by jstimpfle 8y ago
> Which requires you to know that you can declare a type & an instance of that type in a single statement
struct A {
int i;
};
const struct A default_A = { 0 };
Why didn't you try the obvious simple thing first?
The whole undertaking is pointless in any case. Why would you need default values (i.e. templates for constructors) baked in? The only reasonable default value, sometimes, is all-zeroes (or all-ones...).
Now, constant data (i.e. things that contain more useful information than just "it's the default because a real value is missing" -- and that aren't copied around pointlessly) is another case, and C's plain old value initializer syntax (as demonstrated above) serves it perfectly well.
- kllrnohj 8y ago> The only reasonable default value, sometimes, is all-zeroes (or all-ones...). That's very false. Consider a basic string container with a small-size optimization. The default value for capacity is neither 0 nor 1, but the size of the inline array. Similarly it could be an enum value, and the default for a given class isn't whatever the 0 value happened to line up with because that's arbitrary anyway. An example being a basic type id of a fixed number of types.