Ghashtable storing double

2019-07-18 19:35发布

Hello I was wondering if it was possible to store a double into a ghashtable considering there is no gdouble_to_pointer methdod. I am following a tutorial I found online by IBM http://www.ibm.com/developerworks/linux/tutorials/l-glib/section5.html , but I can't seem to find a way to use an int as a key and a double as the value being stored. Any help would be great thanks!

标签: c double glib
1条回答
forever°为你锁心
2楼-- · 2019-07-18 20:20

If you want to use an int as a key, you should use g_int_hash() and g_int_equal() when you create the GHashTable.

As far as using doubles for values goes... you can't. The problem is that you cannot guarantee that sizeof (void *) >= sizeof (double), so you can't use a trick like GINT_TO_POINTER()

查看更多
登录 后发表回答