Re: [Vala] array declaration



Am 07.07.2010 18:33, Harry Van Haaren wrote:
Hey,

Coming from a C++ background I first tried   typeHere  nameHere[];  too.
I noticed that newer languages seemed to have   type[]  name; configuration
(Java, C# etc).

Vala supports two types of arrays:

1) dynamically heap-allocated arrays:

Vala, Java, C#: int[] a = new int[5];
C++: int* a = new int[5];
C: int* a = malloc (5 * sizeof (int));


2) inline/stack-allocated fixed-size arrays:

Vala: int a[5];
C++: int a[5];
C: int a[5];
Java: not supported
C#: unsafe { int* a = stackalloc int[5]; }


@pancake: 'new' combined with the latter type of array does not make
sense, since the 'new' keyword stands for dynamic alloation on the
heap. The Vala compiler should refuse to compile something like
'int a[] = new int[5]'. So it's obviously a bug.


Best regards

Frederik



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