Re: g_list_prepend() vs g_list_append()



Mark Mielke <mark mark mielke cc> writes:

> I assume that g_list_prepend() and g_list_append() are functions that
> only function reliably, and intuitively, if they are passed the 'first
> element in the list', however, their implementations cause me to suspect
> that either this limitation was not intended, or else, the implementation
> of g_list_prepend() can be optimized slightly.

You are always expected to pass the first element of the list into every
g_list_* function.  Passing an intermediate element isn't expected.

We could put:

if (list != NULL)
  g_return_val_if_fail (list->prev == NULL, NULL);


in to catch usage errors like you ran into.

Thanks
-Jonathan



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