So, structs can have default initializers. As far as I understand, however, typedefs should not be able to. Nonetheless, the following compiles (C++11, g++ 5.4, 6, and 7).
typedef struct {
uint8_t foo[6] = {'M', 'A', 'R', 'K', 'E', 'R'};
uint8_t bar;
uint32_t baz;
} MyStruct;
Is the compiler defining and declaring an anonymous struct of type MyStruct with a default initialzer for foo? If so, are bar and baz zero-initialized or uninitialized (CLion warns that bar and baz are uninitialized, but I suspect that is erroneous)? Is this undefined behavior, a g++ extension, or a feature of the language?
Aucun commentaire:
Enregistrer un commentaire