Re: g_value_new Macro?



On 26/08/04 14:22, Ryan McDougall wrote:

Hi,

I use the following in my code. Is there a reason why its not in the
GValue API? Is it evil? If not, wouldn't it be nice to include it?

#define	g_value_new(type)	g_value_init (g_new (GValue, 1), type)
In most of the GValue-using code in existence, the GValues are allocated on the stack, and people do this:
   GValue value = { 0, };
   g_value_init(&value, type);
   /* do stuff with the value */
   g_value_unset(&value);

Also, your macro looks like it might break sometimes. The g_value_init() function expects the GValue to be zeroed out (the type field at a minimum), and g_new() doesn't guarantee this. replacing it with g_new0() would fix this problem.

If you are doing this for your tutorial, it would probably be better to document the common usage of GValues rather than using a non standard g_value_new() macro.

James.

--
Email: james jamesh id au
WWW:   http://www.jamesh.id.au/





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