It is common to use {0}
to initialize a struct
or an array
but consider the case when the first field isn't a scalar type. If the first field of struct Person
is another struct
or array, then this line will result in an error (error: missing braces around initializer
).
struct Person person = {0};
At least GCC allows me to use an empty initializer list to accomplish the same thing
struct Person person = {};
But is this valid C code?
Also: Is this line guaranteed to give the same behavior, i.e. a zero-initialized struct
?
struct Person person;
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…