Re: [Vala] Variable-length array in struct and initializing an array of such structs



Thanks for your reply!

I don't have the definitive answer, but a quick read of your email
makes me wonder why you are using const for a dynamic array.
As I understand it const indicates the variable content 
does not change at run time, i.e. it is not dynamic.

I did it because it's written this way in the FAQ [1]:
 const YourStruct[] s = { { value1, value2, ... }, ...};
I figured it works the same way as single-dimensional const arrays in C,
where the array length doesn't have to be specified too (but the length
is fixed anyway).

I just tried manually specifying the size:
 const Test tests[2] = {
 ...
but it doesn't seem to make a difference (same assertion failure).

Maybe I didn't word myself properly: the array I want to be "dynamic" is
the array inside the structs (called "array" in the examples). Some
functions are bound to two keys, some to three etc. "Dynamic" in this
case meaning I want them to be of variable length at compile time. At
run-time I'm not doing anything with their lengths.

For example, as you can see in example_1 I provided in my previous
message, the array in one struct contains {1, 2, 3} (three elements)
while the other array contains {2, 3} (two elements).

In the end it comes down to an issue of merely semantical value, but I
was wondering whether I should file a bug report for it or if it's just
not allowed in Vala. It just bugs me that example_1 doesn't work, while
it does work if I initialize the arrays outside of the struct
initialization (see attachment).

Thanks,
Steef

[1] https://wiki.gnome.org/Projects/Vala/FAQ#How_do_I_create_an_array_of_structs.3F

Attachment: example_3.vala
Description: Text document



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]