Inserting non-pod struct into a GHashTable

Posted by RikSaunderson on Stack Overflow See other posts from Stack Overflow or by RikSaunderson
Published on 2010-04-19T10:32:47Z Indexed on 2010/04/19 12:13 UTC
Read the original article Hit count: 303

Filed under:
|
|
|

Hi there, I'm trying to build a GHashTable of instances of a struct containing ints, a time_t and a few char*'s.

My question is, how do you insert an instance of a struct into a GHashTable? there are plenty of examples of how to insert a string or an int (using g_str_hash and g_int_hash respectively), but I'm guessing thatI want to use the g_direct_hash, and I can't seem to find any examples of that.

Ideally, my code would look like this:

GHashtable table;
table = g_hash_table_new(g_direct_hash, g_direct_equal);
struct mystruct;
mystruct.a = 1;
mystruct.b = "hello";
mystruct.c = 5;
mystruct.d = "test";

g_hash_table_insert(table,mystruct.a,mystruct);

Clearly, this is incorrect as it does not compile. Can anyone provide an example that does do what I want? Thanks, Rik

© Stack Overflow or respective owner

Related posts about c

    Related posts about glib