Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   glib: problem with GArray (http://www.velocityreviews.com/forums/t435568-glib-problem-with-garray.html)

Erwan Loisant 10-22-2004 06:32 AM

glib: problem with GArray
 
Hello.

I can't properly add elements to a GArray. Basically I have a GArray
of GList, so here is what I do to append an element in a given GList
of my GArray:

1. GList* currentBucket = g_array_index (buckets, GList*, index);
2. currentBucket = g_list_append(currentBucket, node);
3. g_array_insert_val(buckets, index, currentBucket);


1) Get the GList* at the "index" position
2) Append the "node" element in my GList
3) Put back the pointer to GList in the GArray (I think it is needed
especially for the first insertion, since currentBucket is NULL).

The problem is, each time I try to insert a new element, the
"currentBucket" that I get is NULL. For the first insertion at a given
level it's ok, but after that I am supposed to receive a non-null
GList.

Can you see what is the problem?

Joona I Palaste 10-22-2004 07:36 AM

Re: glib: problem with GArray
 
Erwan Loisant <eloisant@gmail.com> scribbled the following
on comp.lang.c:
> Hello.


> I can't properly add elements to a GArray. Basically I have a GArray
> of GList, so here is what I do to append an element in a given GList
> of my GArray:


Please ask platform-specific questions on platform-specific
newsgroups, thanks.

--
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"And according to Occam's Toothbrush, we only need to optimise the most frequent
instructions."
- Teemu Kerola

Richard Bos 10-22-2004 07:45 AM

Re: glib: problem with GArray
 
eloisant@gmail.com (Erwan Loisant) wrote:

> I can't properly add elements to a GArray. Basically I have a GArray
> of GList, so here is what I do to append an element in a given GList
> of my GArray:


> Can you see what is the problem?


Yes. The problem is that neither GArray (Who he? A glamrock singer?) and
GList (The Wicked Witch of the Nor'norwest?) are part of ISO C, so this
question cannot possibly be answered reliably in comp.lang.c unless you
provide us with their definitions.

Richard

Erwan 10-22-2004 07:52 AM

Re: glib: problem with GArray
 
Hello again.

Please excuse me for this mistake.


Larry I Smith 10-22-2004 03:03 PM

Re: glib: problem with GArray
 
Erwan Loisant wrote:
> Hello.
>
> I can't properly add elements to a GArray. Basically I have a GArray
> of GList, so here is what I do to append an element in a given GList
> of my GArray:
>
> 1. GList* currentBucket = g_array_index (buckets, GList*, index);
> 2. currentBucket = g_list_append(currentBucket, node);
> 3. g_array_insert_val(buckets, index, currentBucket);
>
>
> 1) Get the GList* at the "index" position
> 2) Append the "node" element in my GList
> 3) Put back the pointer to GList in the GArray (I think it is needed
> especially for the first insertion, since currentBucket is NULL).
>
> The problem is, each time I try to insert a new element, the
> "currentBucket" that I get is NULL. For the first insertion at a given
> level it's ok, but after that I am supposed to receive a non-null
> GList.
>
> Can you see what is the problem?


Try the GTK mailing lists found at:

http://www.gtk.org

or the GNOME mailing lists found at:

http://www.gnome.org

Regards,
Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.

Erwan Loisant 10-22-2004 03:51 PM

Re: glib: problem with GArray
 
Thank you.

I finally found what was the problem. "g_array_insert_val" actually
inserts the element while I thought it replaced the existing one.



All times are GMT. The time now is 06:01 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.