title: Binary tree in C using only pointers
body: <p>I'm working on a homework assignment in C and I think that a binary search tree would be the best way to implement my solution. The problem is we aren't allowed to define structs or any compound data types, so no </p>
  
  <pre><code>struct TreeNode {
      struct TreeNode* parent;
      struct TreeNode* left;
      struct TreeNode* right;
      int key;
      int value;
  }
  </code></pre>
  
  <p>or anything like that.</p>
  
  <p>The tree will have to be entirely implemented with pointers, so I've been trying to define a number of macros to make navigating and editing the tree easier, such as this one to get a pointer to the parent of a node (where the pointers are void pointers):</p>
  
  <pre><code>#define PARENT(ptr) *(void *)(ptr+ALIGNMENT)
  </code></pre>
  
  <p>The problem, of course, is that you can't dereference void pointers. My question is: if you have a void pointer to a location in memory where another void pointer is stored, how can you read that stored pointer.</p>
  
  <p>Or if that's impossible, is there a better way to do this tree?</p>