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



From: Steef Hegeman <steefhegeman hotmail com>
Sent: Thursday, 23 July 2015, 20:56
Subject: Re: [Vala] Variable-length array in struct and initializing an array of such structs

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).

Hmmm, I have tried your example and changed it so the arrays are the same length
and the same error occurs. So I think the problem is initializing a
nested array within a struct within an array rather than because they are
different lengths.

As an aside, I usually think dynamic is run-time and static is compile time.
So, for example, we talk of statically typed computer languages and dynamically 
typed languages. I imagine, however, you already knew that.



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).
Yes, the semantics are nice when initializing the array inline.
As you are getting a failed assertion from the compiler's codegen
array module then this would be a bug. The assertions are there to 
check for invariant conditions of course. On the other hand I
don't know what the compiler should do instead. The squiggly
braces can signify either a struct or an array which can be 
ambiguous for the parser. So either a better error or get the
semantic analyser to make it right?

For your use case would a hash map ( 
https://wiki.gnome.org/Projects/Vala/GeeSamples#Map_Example ) be better? 

Each key press sequence can be represented as a string and this 
would then map to a delegate containing the relevant function.

All the best,

Al


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