I have a structure with multiple members inside of it that I can't seem to be able to define after declaring it in a separate statement. For simplicity sake, suppose it looks like the following
typedef struct
{
int number;
int anotherNumber;
char character;
char anotherCharacter;
} MY_STRUCTURE_t;
It seems like I should be able to declare the structure and define it later on, as I would do with a variable of a simpler type. For example,
MY_STRUCTURE_t my_structure;
my_structure = {
.number = 1,
.anotherNumber = 42,
.character = '\0',
.anotherCharacter = 'a'
};
The code above generates an error: "Invalid redeclaration of "my_structure"". Fair enough, the compiler knows better. On the other hand, the following code works fine.
MY_STRUCTURE_t my_structure = {
.number = 1,
.anotherNumber = 42,
.character = '\0',
.anotherCharacter = 'a'
};
What is the problem with the snippet in the middle? Is there a fundamental flaw that I am missing?