GNOME Bugzilla – Bug 597817
array in struct initialization produce uncompilabel code
Last modified: 2017-03-09 21:42:07 UTC
Hello I attached a test.vala file that do not compile To resume I create a struct with an array then I try to initialize it using members of another struct, like this struct VectorA { double data[3];} VectorA veca = {{other.x, other.y, other.z}}; the C code generated produce this: struct _VectorA { double data[3]; }; and the wrong part 90:veca = (_tmp1_.data = {vec.x, vec.y, vec.z}, _tmp1_); the error message is: picca@grisette:/tmp$ valac test.vala /tmp/test.vala.c: In function ‘_main’: /tmp/test.vala.c:90: error: expected expression before ‘{’ token error: cc exited with status 256 Compilation failed: 1 error(s), 0 warning(s) is it normal or I did something wrong ? thanks Frédéric
I can not attach the file ??? so I copy here the content (short) struct VectorA { double data[3]; } struct VectorB { double x; double y; double z; } void main() { VectorB vec= {1, 2, 3}; VectorA veca = {{vec.x, vec.y, vec.z}}; assert (veca.data[0] == 1); assert (veca.data[1] == 2); assert (veca.data[2] == 3); }
*** Bug 722754 has been marked as a duplicate of this bug. ***
*** This bug has been marked as a duplicate of bug 741491 ***