title: How do I check if a variable is of a certain type (compare two types) in C?
body: <p>In C (not C++/C#) how do I check if a variable is of a certain type?</p>
  
  <p>For example, something like this:</p>
  
  <pre><code>double doubleVar;
  if( typeof(doubleVar) == double ) {
      printf("doubleVar is of type double!");
  }
  </code></pre>
  
  <p>Or more general: How do I compare two types so that <code>compare(double1,double2)</code> will evaluate to true, and <code>compare(int,double)</code> will evaluate to false. Also I'd like to compare structs of different composition as well.</p>
  
  <p>Basically, I have a function that operates on variables of type "struct a" and "struct b". I want to do one thing with the "struct a" variables and the other with the "struct b" variables. Since C doesn't support overloading and the <code>void</code> pointer losses its type information I need to check for type. BTW, what would be the sense in having a <code>typeof</code> operator, if you can't compare types?</p>
  
  <hr/>
  
  <p>The sizeof method seems to be a practical workaround solution for me. Thanks for your help. I still find it a bit strange since the types are known at compile time, but if I imagine the processes in the machine I can see, why the information is not stored in terms of types, but rather in terms of byte size. Size is the only thing really relevant besides addresses.</p>