Re: [Vala] Static array initialization



First of all, thank you for your help, your code works for me and
declaring the array as const is certainly more appropriate here.

However, I'd like to point out that C allows initialization of arrays of
any type, f.e.

int main (int argc, char ** argv)
{
  struct {
    int a;
    char *b;
  } x[] = {
    { 1, "111" },
    { 2, "222" }
  };

  return 0;
}

runs perfectly, and you can declare x[] as static, const or whatever.
Thinking about it, what reason is there to not allow initialization of
non-const arrays?

Cheers,
Dominique

Raffaele Sandrini schrieb:
Ok this one is tricky ;). The point is that the programm above is
incorrect. You are not allowed to create non const arrays of structs.
This is also not allowed in C. Nevertheless valac does not complain
about that (as of many other things) ;).

The correct array initialisation would be:
        const Gtk.ActionEntry[] entries = {
                { "FileMenu", null, "_File", null, null, null },
                { "EditMenu", null, "_Edit", null, null, null },
              null
        };

have fun
Raffaele





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