Is it valid C to declare a struct and define values enclosed in {}?
struct name new_name[] {
{"value1"},
{"value2"},
{"value3"},
}
Where:
struct name {
union {
char *value1;
} n_u;
char *value2;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What you’ve posted is invalid because it’s missing an equals sign before the initializer (and also trailing semicolons). Otherwise, it’s legal but somewhat hard to read because it doesn’t initialize every field, and doesn’t use a full set of braces. In a fully-braced initializer, you’ll have a pair of braces around the list of values for every array, struct, or union. In this case you have an array of structs with unions in them, so there should be 3 levels of braces for optimum readability. An equivalent with everything spelled out is: