title: C++: Declaration of "extern reference"
body: <p>I want to declare a variable as <code>extern double&amp;</code> and use it's pointer in a <code>static const struct</code>. Somewhere else I want to define the variable to be actually a member of another struct. The code attached works on <code>x86</code> as I expect.</p>
  
  <p>Problem is that it does not work in an embedded <code>ARM</code> context: The <code>void* void_pointer</code> inside the initialized <code>static const struct</code> there is just <code>NULL</code>, while everything else looks valid.</p>
  
  <p>Is the syntax I try here possible and defined in the Standard, or some detail implementation defined? How would I debug this? What can go wrong? What is actually happending here?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  // declare and define place where the actual content is stored
  struct storage_struct { double double_array[2]; double double_variable; };
  struct storage_struct db = {{3.0,4.0},1.0};
  
  // declare "double_reference" as extern
  extern double &amp;double_reference;
  
  // declare and defince a struct to hold the pointer to the extern reference:
  struct target_struct { void *void_pointer; };
  static const struct target_struct dut { &amp;double_reference };
  
  // and now connect the "extern refernce" to an actual value from the database-struct
  double &amp;double_reference = db.double_variable;
  
  int main() {
  
      std::cout &lt;&lt; "testPrint with initial values:\n";
      std::cout &lt;&lt; "void pointer: '" &lt;&lt; dut.void_pointer &lt;&lt; "', value: '"
                &lt;&lt; *(double *)dut.void_pointer &lt;&lt; "'\n";
      std::cout &lt;&lt; "\n";
  
      // change content in the database
      db.double_variable = 11.0;
      db.double_array[0] = 1444.0;
      db.double_array[1] = 238947.0;
  
      std::cout &lt;&lt; "adress of storage_struct: " &lt;&lt; &amp;db &lt;&lt; "\n";
      std::cout &lt;&lt; "adress of double_variable: " &lt;&lt; &amp;db.double_variable &lt;&lt; "\n";
      std::cout &lt;&lt; "adress of double_reference: " &lt;&lt; &amp;double_reference &lt;&lt; "\n";
      std::cout &lt;&lt; "\n";
  
      std::cout &lt;&lt; "testPrint with changed values:\n";
      std::cout &lt;&lt; "void pointer: '" &lt;&lt; dut.void_pointer &lt;&lt; "', value: '"
                &lt;&lt; *(double *)dut.void_pointer &lt;&lt; "'\n";
      std::cout &lt;&lt; "\n";
  
      return 0;
  }
  </code></pre>
  
  <p>Compile and execute with: <code>g++ -std=c++11 -o test main.cpp &amp;&amp; ./test</code> -- works like a charm. Flash this to an ARM <strong>µC</strong> -- <code>void_pointer</code> is 0x00... (Note that it also works on Debian <code>ARM</code>)</p>