title: Pointer to a global static variable - not safe?
body: <p>I have file in which I have a global array</p>
  
  <pre><code>static char name[6];
  </code></pre>
  
  <p>and a function</p>
  
  <pre><code>static char* gen_name(char* dest, const size_t len) {
      for (int i = 0; i &lt; len - 1; ++i)
          dest[i] = 'A' +  (genrand_uint32() % ('Z' - 'A'));
      dest[len - 1] = '\0';
      return dest;
  }
  </code></pre>
  
  <p>The pointer to the name is then stored in a global variable in different header file, this variable is not static.</p>
  
  <pre><code>this_name = gen_name(name, sizeof name);
  </code></pre>
  
  <p>When a function in another file uses this pointer, it works well on Linux, but when I run the same code on a microcontroller, it prints garbage.
  When I remove the <code>static</code> keyword, it works fine.</p>
  
  <p>Why is this happening?</p>
  
  <p>When should I use <code>static</code>?
  I thought I should declare all variables and functions that are not used outside of a file as <code>static</code>, is this wrong?</p>