Re: Abuse of 'const' ?



hi John,

On 2013-04-08 04:44, John Emmas wrote:
// glib/gvariant.h
GLIB_AVAILABLE_IN_ALL
const gchar **g_variant_get_bytestring_array (GVariant *value, gsize
*length);


// glib/gvariant.c
static gpointer
g_variant_valist_get_nnp (const gchar **str, GVariant *value)
{
         // some stuff
         return g_variant_get_bytestring_array (value, NULL);
}


A 'const gchar **' is (in this case) an array of 'const gchar *' (ie: const string pointers). It is the strings that are immutable. The array itself is fully writable, and indeed you should free what g_variant_get_bytestring_array() returns to you, using g_free().

By the same token it is therefore perfectly acceptable to pass it through a gpointer.

Cheers


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