title: glib2 hash table: GINT_TO_POINTER macro
body: <p>I don't think I understand the glib2's hash table, in particular, how to properly use GINT_TO_POINTER when both key and value are integers. I would think this is a use case for using <code>g_int_hash</code> and <code>g_int_equal</code> when you create a new hash table. However,the following snippet will seg faults.</p>
  
  <pre><code>#include &lt;glib.h&gt;
  
  int main(void) {
      GHashTable * freq = g_hash_table_new(g_int_hash, g_int_equal);
      for (int i = 0; i &lt; 10; i++) {
          g_hash_table_insert(freq, GINT_TO_POINTER(i), GINT_TO_POINTER(0));
      }
      g_hash_table_destroy(freq);
  }
  </code></pre>
  
  <p>I know two ways to make it right: one is to create a hash table like this without changing anything else:</p>
  
  <pre><code>   GHashTable * freq = g_hash_table_new(g_direct_hash, g_direct_equal);
  </code></pre>
  
  <p>A second way is, keep creation as it is, but explicitly allocate space for both key and value:</p>
  
  <pre><code>   int * key = malloc(sizeof(int));
     int * value = malloc(sizeof(int));
  </code></pre>
  
  <p>then insert the key and value by casting it to (gpointer).</p>
  
  <p>The second approach seems like a really tedious way of doing a  key value pair, is this the proper way of doing <strong>int to int</strong> mapping? Thanks.</p>