I have a strange behaviour of the compiler, resulting in a wrong initialization of a struct.
Here is the simple program: Please note the order of the designated initializer in the initialization.
Code: Select all
/**
* @file main.c
* @brief Main function for StructInitialization application.
*/
typedef struct
{
int var1;
int var2;
int var3;
int var4;
} my_struct_t ;
my_struct_t a = {
.var1 = 1,
.var2 = 2,
.var4 = 5,
.var3 = 7,
} ;
int main(void)
{
/* Replace with your application code */
while (1)
{
a.var1 = 0 ;
}
return 0;
}
Code: Select all
var1 : 0
var2 : 2
var3 : 7
var4 : 5
Code: Select all
var1 : 0
var2 : 2
var3 : 5
var4 : 7
Please advice.
best regards
Frank