Comment by WalterBright

1 month ago

D is consistent in that structs also default initialize:

    struct S { int a; float f; }
    S s;

For C, having an error when the initializer is omitted is better than nothing. However, that is not part of the C Standard, and you'll be relying on having a C compiler with that extension. Otherwise there is undefined behavior. To do it right means it needs to be standardized.

Sorry, but I wouldn't like that either. I often intentionally don't initialize members and don't want that to be an error. How would you initialize the following:

    struct S  {
         enum {
              NO_MODE,
              MODE_A,
              MODE_B,
              MODE_C,
         } mode;
         union {
             struct mode_a {
                 float x, y;
             } a;
             struct mode_c {
                 time_t start;
                 bool flag;
             } c;
         };
    };

    S s;
    s.mode = NO_MODE;

?