title: C macro get typeof argument
body: <p>I am trying to write a macro to assist with object oriented programming in C. As I store the class information in a constant struct, I need to create a macro that does the following:</p>
  
  <ul>
  <li>Take the type of the object (typeof the derefenced pointer)</li>
  <li>Append <code>_info</code> to get the name of the desired classInfo struct</li>
  <li>Take the address of that symbol so it can be passed to the function</li>
  <li>Call the <code>destroyObject</code> function with a pointer to the class struct and the object itself</li>
  </ul>
  
  <p>An example:</p>
  
  <pre><code>queue_t* p = NULL;
  delete(p);
  </code></pre>
  
  <p><code>delete</code> should expand to:</p>
  
  <pre><code>destroyObject(&amp;(queue_t_info), p);
  </code></pre>
  
  <p>I tried using this macro, but I can't get to to work:</p>
  
  <pre><code>#define delete(X) (destroyObject(&amp;(typeof(*X)##_info), X))
  </code></pre>
  
  <p>I'm having trouble with the typeof part to work correctly. </p>