Re: [Vala] Static array initialization



Hi there

On Mit, 2007-03-07 at 20:34 +0100, Dominique Würtz wrote:
Hi again,

I run into problems when trying to initialize a static array.

using Gtk;

public class Test
{
      static Gtk.ActionEntry[] entries = {
              { "FileMenu", null, "_File", null, null, null },
              { "EditMenu", null, "_Edit", null, null, null }
      };
      
      static int main (string[] args) {

      }
}

I'm not even sure if this is the correct syntax, but then, Vala doesn't
complain. The generated C code however is clearly wrong and results in a
crash once you try to access the array.
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]