title: Dereferencing pointer to incomplete type 'struct ____'
body: <p>I am attempting to create a type in C that can accept most primitive types. I am new to C and don't understand structs very well. My error occurs on line 10 (of main.c) and it will also occur on line 11 if line 10 is removed (also of main.c). If anyone has an ideas/pointers I would really appreciate it! Many thanks!</p>
  
  <p>main.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #include "modularType.h"
  
  int main()
  {
      int data = 1;
  
      PyType object = createPyObjectInt(data);
      printf("Type of data:  %d\n", object-&gt;typeOfData);
      printf("Value of data: %d\n", object-&gt;intData);
  
      return 0;
  }
  </code></pre>
  
  <p>modularType.h:</p>
  
  <pre><code>typedef struct pytype *PyType;
  
  PyType createPyObjectEmpty(void);
  PyType createPyObjectInt(int data);
  
  void setDataInt(PyType, int data);
  void setDataIntStar(PyType, int* data);
  
  void freeMyType(PyType);
  void freeCharStar(PyType);
  void freeIntStar(PyType);
  void freeFloatStar(PyType);
  </code></pre>
  
  <p>modularType.c:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  #ifndef NEW_TYPE
  #define NEW_TYPE
  
  #include "modularType.h"
  
  typedef enum
  {
      NO_DATA,
      REG_CHAR,
      CHAR_STAR,
      REG_INT,
      INT_STAR,
      REG_FLOAT,
      FLOAT_STAR,
  }types;
  
  struct pytype
  {
      //The number of data types i can hold here
      unsigned char typeOfData: 3;
  
      union
      {
          char   charData;
          char*  charStarData;
          int    intData;
          int*   intStarData;
          float  floatData;
          float* floatStarData;
      }
  };
  
  PyType createPyObjectEmpty(void)
  {
      PyType object;
  
      object = malloc(sizeof(*object));
  
      object-&gt;typeOfData = NO_DATA;
  
      return object;
  }
  
  PyType createPyObjectInt(int data)
  {
      PyType object;
  
      object = malloc(sizeof(*object));
  
      object-&gt;intData = data;
      object-&gt;typeOfData = REG_INT;
  
      return object;
  }
  
  void setDataInt(PyType object, int data)
  {
      object-&gt;intData    = data;
      object-&gt;typeOfData = REG_INT;
  }
  
  void setDataIntStar(PyType object, int* data)
  {
      object-&gt;intStarData = data;
      object-&gt;typeOfData  = INT_STAR;
  }
  
  #endif
  </code></pre>
  
  <p>As a side note my compilation command (gcc -Wall -std=c99 -o modType main.c modularType.c) produces the following warning: <strong>modularType.c:35:1: warning: no semicolon at end of struct or union</strong>. I thought that I had formatted my struct correctly but I have also seen people define structs as following: </p>
  
  <pre><code>typedef struct pytype
  {
      //code here
  }PyType;
  </code></pre>
  
  <p>Is this a better way or is the way I am doing it fine?</p>