Sorry for bad English.
Suppose the code (C99 or later):
typedef struct {
int a, b;
} foo_t;
foo_t f = { .a = 1, .b = 2 };
f = (foo_t){ .b = 3 };
What is f.a now? Does C standard say anything about this?
I know that for partial initialization the standard guarantees all uninitialized members will be initialized to “appropriate zero” (0 for integers, 0.0 for floating, NULL for pointers, etc.). But the last statement isn’t initialization (as I understand), because f is already exists. I’m confused.
Point 6 in section 6.5.2.5 Compound literals of the C99 standard states:
The unnamed
foo_tis partially initialized, by the same rules you mention.The last statement is an assignment, but the compound literal is an unnamed object initialized by the initializer list. Meaning the
unnamed.ahas value zero andf.ais zero after the assignment.