title: How to make a structure extern and define its typedef
body: <p>I'm trying to implement tree algorithms in C. I have declared a extern struct in a header file that is completely independent (b_tree_ds.h). Now I plan to import the file in all source files that want to use this struct. So I must declare it using extern in header.</p>
  
  <p>Now the problem is thhat I want to define its typedef as well. the compiler gives error of multiple storage classes. How should I do that.</p>
  
  <pre><code>typedef extern struct node {
      struct node* left;
      struct node* right;
      int key;    // contains value
  }NODE;
  </code></pre>
  
  <p>The actual problem is as follow, which I still can't fix???
  I recently learnt how can we use multiple source files with header files to make code portable and hierarchical. In order to do so, I tired creating my tree program using this principal. Here are my files</p>
  
  <p>b_tree_ds.h - This will contain a <em>declaration</em> of datastructure of node of a tree, which can be called to various functions implementing different functionality of the tree (which may be in different source files)</p>
  
  <pre><code>typedef struct node {
      struct node* left;
      struct node* right;
      int key;    // contains value
  }NODE;
  </code></pre>
  
  <p>When i try adding a extern as in typedef <code>extern struct node</code> it gives a error of multiple storage class but if I miss it, I get error for multiple definitions.</p>
  
  <p>Here are my other source files</p>
  
  <p>traverse.h  - contains declaration of traverse function</p>
  
  <pre><code>void traverse_print (NODE* p);
  </code></pre>
  
  <p>Here also I get error for unknown identifier NODE</p>
  
  <p>traverse.c - contains definition to that function</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "b_tree_ds.h"
  #include "traverse.h"
  
  void traverse_print(NODE* p)
  {
      if(p-&gt;left != NULL)
      {
          traverse_print(p-&gt;left);
      }
  
      if (p-&gt;right != NULL)
      {
          traverse_print(p-&gt;right);
      }
  
      printf ("\n%d",p-&gt;key);
  }
  </code></pre>
  
  <p>Finally main.c </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "traverse.h"
  
  void main()
  {
      // input
      NODE p;
  
      printf("\nInput the tree");
      input_tree (&amp;p);
  
      printf("\n\nThe tree is traversing ...\n")
      traverse_print(&amp;p);
  }
  
  void input_tree (NODE *p)
  {
      int in;
      int c;
      NODE *temp;
  
      printf("\n Enter the key value for p: ");
      scanf("%d", &amp;in);
      p-&gt;key  =in;
      printf ("\n\nIn relation to node with value %d",in);
      printf ("Does it have left child (Y/N): ")
      if ((c = getchar()) == Y);
      {
          //assign new memory to it.
          temp = (NODE *)malloc(sizeof(NODE));
          input_tree(temp);
      }
      printf ("\n\nIn relation to node with value %d",p-&gt;key);
  
      printf ("\nDoes it have right child (Y/N): ")
      if ((c = getchar()) == Y);
      {
          //assign new memory to it.
          temp = (NODE *)malloc(sizeof(NODE));
          input_tree(temp);
      }
  }
  </code></pre>
  
  <p>This is my first attempt to such practice, please suggest is the structuring of my program good or should I try something else.</p>