Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > glib: problem with GArray

Reply
Thread Tools

glib: problem with GArray

 
 
Erwan Loisant
Guest
Posts: n/a
 
      10-22-2004
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?
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      10-22-2004
Erwan Loisant <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"And according to Occam's Toothbrush, we only need to optimise the most frequent
instructions."
- Teemu Kerola
 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      10-22-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (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
 
Reply With Quote
 
Erwan
Guest
Posts: n/a
 
      10-22-2004
Hello again.

Please excuse me for this mistake.

 
Reply With Quote
 
Larry I Smith
Guest
Posts: n/a
 
      10-22-2004
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.
 
Reply With Quote
 
Erwan Loisant
Guest
Posts: n/a
 
      10-22-2004
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments