title: C: "invalid use of undefined type ‘struct X’ & dereferencing pointer to incomplete type" errors
body: <p>I've been perusing similar questions to mine for a couple of days but still haven't found a solution. Thanks any any help:</p>
  
  <p>I have two files, one containing methods for dealing with rational numbers and one that handles them in a 2 dimensional array. My problem is matrix.c doesn't recognize the fraction structure in contained in fraction.c. I believe my problem is somehow related to the way I declared my 2d array.</p>
  
  <p>In fraction.c:</p>
  
  <pre><code>struct fraction {
     int integer;
     int num;
     int den;
  };
  typedef struct fraction* fractionRef;  //This line is in fraction.h
  </code></pre>
  
  <p>In matrix.c:</p>
  
  <pre><code>#include "fraction.h"
  
  typedef struct matrix* matrixRef;
  
  struct matrix {
     int rows;
     int columns;
     fractionRef *m;
  }matrix;
  
  matrixRef new_matrix ( int rows, int columns ) {
     matrixRef matrix;
     matrix = (matrixRef)malloc( sizeof( matrix ) );
     matrix-&gt;m = (fractionRef*)calloc( rows, sizeof( fractionRef ) );
     int i;
     for ( i=0; i&lt;=rows; i++ )
       matrix-&gt;m[i] = (fractionRef)calloc( columns, sizeof( fractionRef ) );
     assert( matrix-&gt;m );
     return matrix;
  
  }
  void free_matrix ( matrixRef freeMe ) {
     if ( freeMe != NULL ){
        int i, j;
        for( i = 0; i &lt;= freeMe-&gt;rows; i++ ){
           for ( j = 0; j &lt;= freeMe-&gt;columns; j++ ){
              free_fraction( freeMe-&gt;m[i][j] ); //ERROR OCCURS HERE
           }
        }
        freeMe-&gt;rows = 0;
        freeMe-&gt;columns = 0;
        free(freeMe);
        freeMe = NULL;
     }
  }
  </code></pre>
  
  <p>The error I get corresponds to the line in matrix.c I marked.</p>
  
  <pre><code>matrix.c:47: error: invalid use of undefined type ‘struct fraction’
  matrix.c:47: error: dereferencing pointer to incomplete type
  </code></pre>
  
  <p>This is probably all because I learned java BEFORE c, big mistake!!! Thanks again for any help.</p>
  
  <p>EDIT: Thanks everyone. So the way I see it now is everything in the header .h files are similar to public in java. My fraction struct definition wasn't "public" to the c compiler so my matrix.c wasn't able to access it.</p>