Question

In Vala, some methods require an Array of uint8's (uint8[]) as a parameter. For example see http://valadoc.org/#!api=glib-2.0/GLib.FileStream.write

I have the following code, but no idea how to "cast" my value to an array:

...
uint8 some_integer = 7;
desc.write(???, 1);
...

In C I'd simply do:

 ...
uint8 some_integer = 7;
fwrite(&some_integer, 1, 1, desc);
...

but the Vala compiler is not amused about the &-operator. What to do?

Was it helpful?

Solution

You can create an array in Vala as int[] b = { 2, 4, 6, 8 };. Hence you should be able to create it with a single variable too as uint8 [] some_array = {some_integer};; in your case desc.write({some_integer}, 1);.

Here's a detailed guide on Vala for further references.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top