Ghashtable storing double

不打扰是莪最后的温柔 提交于 2019-12-11 00:19:48

问题


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!


回答1:


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()



来源:https://stackoverflow.com/questions/6682731/ghashtable-storing-double

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!