title: Once-only pseudo-generic header in C
body: <p>After some work on the generic vector I asked about on <a href="https://stackoverflow.com/questions/28974104/trying-to-make-templates-in-c" title="this question">this question</a>, I would like to know if there is any way of checking that each instanciation of the library is only done once per type.</p>
  
  <p>Here is what the current header file looks like:</p>
  
  <pre><code>#ifndef VECTOR_GENERIC_MACROS
  #define VECTOR_GENERIC_MACROS
  
      #ifndef TOKENPASTE
      #define TOKENPASTE(a, b) a ## b
      #endif
  
      #define vector_t(T) TOKENPASTE(vector_t_, T)
  
      #define vector_at(T) TOKENPASTE(*vector_at_, T)
  
      #define vector_init(T) TOKENPASTE(vector_init_, T)
      #define vector_destroy(T) TOKENPASTE(vector_destroy_, T)
      #define vector_new(T) TOKENPASTE(vector_new_, T)
      #define vector_delete(T) TOKENPASTE(vector_delete_, T)
  
      #define vector_push_back(T) TOKENPASTE(vector_push_back_, T)
      #define vector_pop_back(T) TOKENPASTE(vector_pop_back_, T)
      #define vector_resize(T) TOKENPASTE(vector_resize_, T)
      #define vector_reserve(T) TOKENPASTE(vector_reserve_, T)
  
  #endif
  
  typedef struct {
      size_t size;
      size_t capacity;
      TYPE *data;
  } vector_t(TYPE);
  
  inline TYPE vector_at(TYPE)(vector_t(TYPE) *vector, size_t pos);
  
  void vector_init(TYPE)(vector_t(TYPE) *vector, size_t size);
  void vector_destroy(TYPE)(vector_t(TYPE) *vector);
  inline TYPE *vector_new(TYPE)(size_t size);
  inline void vector_delete(TYPE)(vector_t(TYPE) *vector);
  
  void vector_push_back(TYPE)(vector_t(TYPE) *vector, TYPE value);
  inline TYPE vector_pop_back(TYPE)(vector_t(TYPE) *vector);
  inline void vector_resize(TYPE)(vector_t(TYPE) *vector, size_t size);
  void vector_reserve(TYPE)(vector_t(TYPE) *vector, size_t size);
  </code></pre>
  
  <p>The header can then be included along with the source definitions:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #define TYPE int
  #include "vector.h"
  #include "vector.def"
  #undef TYPE
  
  int main()
  {
      vector_t(int) myVectorInt;
      vector_init(int)(&amp;myVectorInt, 0);
  
      for (int i = 0; i &lt; 10; ++i)
          vector_push_back(int)(&amp;myVectorInt, i);
  
      for (int i = 0; i &lt; myVectorInt.size; ++i)
          printf("%d ", ++vector_at(int)(&amp;myVectorInt, i));
  
      vector_destroy(int)(&amp;myVectorInt);
      return 0;
  }
  </code></pre>
  
  <p>I would like to make sure that the content below that last endif is only included once per TYPE.</p>
  
  <p>Obviously, #ifdef VECTOR_INSTANCE(TYPE) does not work, so I'm really out of ideas...</p>