Many of us know that this works:
struct data_s
{
uint32_t p_1;
uint32_t p_2;
uint32_t p_3;
uint32_t p_4;
};
void foo(struct data_s data)
{
printf("p1: %d\r\n", data.p_1);
printf("p2: %d\r\n", data.p_2);
printf("p3: %d\r\n", data.p_3);
printf("p4: %d\r\n", data.p_4);
}
int main(void)
{
foo((struct data_s){
.p_1 = 1,
.p_2 = 2,
.p_3 = 3,
.p_4 = 4});
}
I have seen this many times, but now cannot find anything in C reference manual about it. Is this construct standard or implementation defined?
Also, that type casting is kinda odd, because it is more like "I will tell compiler how and what to allocate and how to arrange it" than "cast that type to this type". Will the data layout in memory of the argument passed to function will be exactly the same as of object created by struct data_s obj;
?