title: Most elegant way to share a C array
body: <p>I have to turn back to (embedded) C after some lengthy time with C++, and have the following problem:</p>
  
  <p>I have a source module which is included a lot of times, let's call it <code>utilities.h</code> and <code>utilities.c</code>
  In it, I have an important array, let's call it </p>
  
  <pre><code>#define IMPORTANT_ARRAY_LENGTH  10000
  char important_array[IMPORTANT_ARRAY_LENGTH];
  </code></pre>
  
  <p>I have a lot of other functions in this <code>utilities</code> module, and they all work fine. However, in one of the other source files, let's call it <code>worker.c</code>, I have to use this array. What is the "official", elegant way to do this, without having to put <code>extern char important_array[IMPORTANT_ARRAY_LENGTH]</code> and the macro definition in the <code>worker.c</code> ?</p>
  
  <p>If I do the following:</p>
  
  <p>utilities.h</p>
  
  <pre><code>#ifndef _UTILITIES_H_
  #define _UTILITIES_H_
  
  #define IMPORTANT_ARRAY_LENGTH  10000
  extern char important_array[IMPORTANT_ARRAY_LENGTH];
  
  // ...
  </code></pre>
  
  <p>utilities.c</p>
  
  <pre><code>#ifndef _UTILITIES_C_
  #define _UTILITIES_C_
  
  #include "utilities.h"
  
  char important_array[IMPORTANT_ARRAY_LENGTH];
  
  // ...
  </code></pre>
  
  <p>worker.c</p>
  
  <pre><code>#include "utilities.h"
  // ...
  important_array[0] = 0;
  </code></pre>
  
  <p>then my array will be an undefined symbol in <code>worker.c</code>. If I don't use the <code>extern</code> keyword in <code>utilities.h</code>, then of course, it's a duplicate symbol. (Strangely, it compiles with just a warning, and I can see from the linker file that the size is allocated multiple times.)</p>
  
  <p>Do I really have to declare my array in <code>worker.c</code>? I want to keep everything clean, and have all declarations in one place only: in a header file. And I want to have the macro definition only once (this is secondary, because I could use a const, but I want the preprocessor to handle it, and not take up place)</p>