I have the following structure:
struct myStruct {
long int mem0;
int mem1;
int mem2;
// -- Place 1 --
short int sh;
-- Place 2 --
char array[5];
// -- Place 3 --
};
I try to initialize it as follows:
struct myStruct ms1 = {
mem0 : 124,
mem1 : 120,
mem2 : 99,
mem3 : 12,
}; // Line 36
If I place any of the following lines in place 2 or place 3
char mem3;
int mem3;
I get the following error:
Azulejo-Main-Engine-1v2-4% g++ test2.cpp -o test2
test2.cpp: In function ‘int main()’:
test2.cpp:36:5: sorry, unimplemented: non-trivial designated initializers not supported
};
^
Azulejo-Main-Engine-1v2-4%
However, If I place it in place 1, my program compiles (and executes as expected). Can you please explain me why this is the case?.
I'm trying to port C code into C++. How can prevent this kind of errors?. I don't have any control on the structure declarations used by the code.
Azulejo-Main-Engine-1v2-4% g++ --version
g++ (GCC) 5.2.0