Re: [Vala] GINT_TO_POINTER



On Thu, Dec 09, 2010 at 11:40:02 -0600, W. Michael Petullo wrote:
Is there a GINT_TO_POINTER-like capability in Vala? Or, if I need
something like this does it mean I am not trying to solve a problem in
a Vala way? In C, I often use this macro to place integers into GLib
datatypes like GHashTable.

Vala uses it automatically with generics.

When you have a structure, that stores a gpointer in C, in vala it's declared
as generic. This tells vala what type you are actually store in the
structure. It also provides the type ID, ref/copy and unref/delete functions
to the structure if it needs them to manipulate the stored data.

If you pass 'int' for the generic parameter, it will be stored using
GINT_TO_POINTER. Any other type must be a reference type; primitive types
larger than int can be boxed by adding '?' to them.

-- 
                                                 Jan 'Bulb' Hudec <bulb ucw cz>



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