title: Declaring a global struct that is created inside a function
body: <p>I have a number of functions that need to share a struct but as the size of the struct is variable I get an error if I declare it outside of all functions, is there a way to declare a struct inside a specific function and have it accessible to all others?</p>
  
  <p>This is what I have so far:</p>
  
  <p>header file:</p>
  
  <pre><code>//  functions.h
  struct Pixel
  {
      int x; // x axis of pixel location
      int y; // y axis of pixel location
      int r; //red
      int g; //green
      int b; //blue
  };
  
  //failed attempt at declaring pixels as global
  extern struct Pixel pixels[];
  </code></pre>
  
  <p>the struct pixels[] is defined inside a separate file which has all the functions that utilize it and includes the above mentioned header file</p>
  
  <pre><code>int Parser(FILE* file)
  {
      // lots of foo 
  
      // structure declaration where linecount is a variable number generated 
      // in another function but declared globally
      struct Pixel pixels[linecount];
  }
  </code></pre>