title: C Structure typedef with Forward Declarations
body: <p>I was using typedef for structures everywhere in my application. I then started to refactor into several
  header files when it started to get clunky. I noticed I needed to forward declare Object, and Klass.
  Well, to my surprise, I couldn't forward declare Object, or Klass. This is because, as you can see in the
  Object and Klass structure, I'm using a typedef of Object and Klass.</p>
  
  <pre><code>//Klass.h
  
  typedef struct Klass Klass_t;
  
  struct Klass
  {
      void (*_initialize)(Object_t* object, Klass_t* klass);
  };
  
  //Object.h
  
  typedef struct Object Object_t;
  
  struct Object
  {
      Klass_t* _klass;
  };
  </code></pre>
  
  <p>At first, using typedef was great. But trying to forward declare Object:</p>
  
  <pre><code>struct Object_t;
  </code></pre>
  
  <p>Doesn't work as I would need to rewrite by function declarations as:</p>
  
  <pre><code>void (*_initialize)(struct Object_t* object, Klass_t* klass);
  </code></pre>
  
  <p>So I decided to just typedef Object inside the Klass.h header file:</p>
  
  <pre><code>typedef struct Object Object_t;
  </code></pre>
  
  <p>Well when all header files are included into my Main.c file, it complians:</p>
  
  <pre><code>Object.h:5: error: redefinition of typedef 'Object_t'
  </code></pre>
  
  <p>So, I then decided to just drop all struct typedefs and explicity declare my structures.</p>
  
  <p>Is there a way to typedef a structure and forward declare in another file without explicitly using struct Object?</p>
  
  <p>I want to keep structure typedefs inside the header file where
  the structure is declared. If I have to group all typedefs inside one header file then I would rather not use typedef at all. Anyways, thanks for your time.</p>