glib: problem with GArray

Discussion in 'C Programming' started by Erwan Loisant, Oct 22, 2004.

  1. 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?
     
    Erwan Loisant, Oct 22, 2004
    #1
    1. Advertising

  2. Erwan Loisant <> 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 () ------------- Finland --------\
    \-------------------------------------------------------- rules! --------/
    "And according to Occam's Toothbrush, we only need to optimise the most frequent
    instructions."
    - Teemu Kerola
     
    Joona I Palaste, Oct 22, 2004
    #2
    1. Advertising

  3. Erwan Loisant

    Richard Bos Guest

    (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
     
    Richard Bos, Oct 22, 2004
    #3
  4. Erwan Loisant

    Erwan Guest

    Hello again.

    Please excuse me for this mistake.
     
    Erwan, Oct 22, 2004
    #4
  5. 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.
     
    Larry I Smith, Oct 22, 2004
    #5
  6. 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.
     
    Erwan Loisant, Oct 22, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel C Bastos

    glib/gtk and the standard

    Daniel C Bastos, Jul 6, 2003, in forum: C Programming
    Replies:
    3
    Views:
    541
    Dan Pop
    Jul 7, 2003
  2. Arjan

    Glib IO channels in Windows

    Arjan, Mar 18, 2005, in forum: C Programming
    Replies:
    2
    Views:
    519
    Mark McIntyre
    Mar 18, 2005
  3. TPJ

    GLib problems

    TPJ, Dec 5, 2005, in forum: C Programming
    Replies:
    0
    Views:
    305
  4. Loic Mahe
    Replies:
    1
    Views:
    1,006
    Spoon
    Jun 8, 2007
  5. akappa

    Serializing a glib data type

    akappa, Aug 19, 2007, in forum: C Programming
    Replies:
    10
    Views:
    598
    Justin Spahr-Summers
    Aug 20, 2007
Loading...

Share This Page