While reading a code I came across, the following definition and initialization of a struct:
// header file
struct foo{
char* name;
int value;
};
//Implementation file
struct foo fooElmnt __foo;
// some code using fooElmnt
struct foo fooElmnt __foo = {
.name = "NAME";
.value = some_value;
}
What does this mean in C and how is it different from usual declarations?
It’s called designated initialization,
If you read on, it explains that
.fieldnameis called a designator.UPDATE: I’m no C99 expert, but I couldn’t compile the code. Here’s the changes I had to make:
Were you able to compile it? I used TCC.