Neither of these snippets of code work:
int main() {
struct mystruct {
int a;
char* b;
char* c;
} e,f;
e = {5, "blaat", "boe"};
return 0;
}
Error: syntax error for ‘{‘ token
int main() {
struct mystruct {
int a;
char* b;
char* c;
} e,f;
struct mystruct e = {5, "blaat", "boe"};
return 0;
}
Error: previous declaration of ‘e’ was here
What is the correct way to do this?
Compound literal assignment is new with C99, and the syntax would be
The cast expression is required.
In C89, you either have to initialize
eas part of the declaration:or
or you have to assign members individually: