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



On Fri, Jul 24, 2015 at 12:23:53AM +0000, Al Thomas wrote:
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.
Ah, you're right. I totally forgot to check for that and simply assumed
that the length was the issue.

It even seems like it's impossible to do so for a const struct too:
 const Test = {2.5, {1, 2, 3} };
raises the same error. I see this has already been reported [1]

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.
Point taken, thanks. I knew the term but it's not as readily available
as it should be, haha.

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?
As it's possible with a non-const struct or array of structs, I think it
would be nice if it were possible with the const variants too. I added a
comment to the bug report, maybe someone else knows what would be right
in this case. (I'm still not entirely sure whether this should be valid
Vala code in the first place)

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.
I thought using a string would mean I had to write a translation
function but it seems there's already one in Gdk [2]. Great idea,
thanks!

I'm probably going to still use an array of structs for it so that I can
initialize it inline. using CCode has_target = false I can use Delegates
in the structs (I had it working with one key before I revised and
realized I wanted multiple keys)

Anyway, thanks for the help! I may dive into the parser code to see if I
can get the inline initialization working (if it's indeed supposed to be
working) but for now I'm going to enjoy defining key bindings.

Thanks for all the help,
Steef

[1] https://bugzilla.gnome.org/show_bug.cgi?id=741491
[2] http://www.valadoc.org/#!api=gdk-3.0/Gdk.keyval_from_name


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