title: How to force compiler to set a non-zero value to uninitialized variables?
body: <p>I am playing with <a href="http://en.cppreference.com/w/cpp/language/value_initialization" rel="nofollow noreferrer">C++ value initialization</a>.<br>
  Therefore, I am printing uninitialized values in order to highlight (un)initialization depending on C++ standard version.<br>
  But uninitialized values convey often the zero value :-(</p>
  
  <p><strong>How to highlight if a variable has not been initialized?</strong><br>
  (i.e., How to say to the compiler to use a specific value for uninitialized variables?)</p>
  
  <p>Maybe this could be done using a <em>magic</em> user-provided allocator...</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> My below snippets is not for production. I just wanted to check the implementation (by the compiler) of the C++ Standard about uninitialization/value-initialization/zero-initialization/default-initialization mechanisms. I do not want compiler warnings about uninitialized variables. I do not want to use MemoryCheckers. I just want to highlight that compiler zero-initializes some variables, default-initializes some other variables and does not initialize at all other variables. And this initialization behavior also depends on the version of C++ Standard. If you think the best way is to use compilers warnings or MemoryCheckers, please provide an answer using the below snippets.</p>
  
  <hr>
  
  <p><sub>Please do not read below detailed attempts if you have already understood my question.</sub></p>
  
  <hr>
  
  <p>You can <a href="http://coliru.stacked-crooked.com/a/4aa1f830f59fa4cd" rel="nofollow noreferrer">build/run my first snippet on Coliru</a></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct A  {
    A() {} // user-defined default ctor does not initialize i
    int i;
  };
  
  struct B {
    A a;
  };
  
  int main()
  {
    std::cout &lt;&lt; B().a.i &lt;&lt; '\n';
      // Results: C++03 -&gt; uninitialized
      //          C++11 -&gt; zero-initialized
  
    std::cout &lt;&lt; B{}.a.i &lt;&lt; '\n';
      // Results: C++03 -&gt; Do not compile - B{} is correct since C++11
      //          C++11 -&gt; uninitialized because
      //          DR1301 defines B{} as an aggregate-initialization
  }   //          =&gt; A is value-initialized using the user-defined ctor
  </code></pre>
  
  <p>When compiled using <code>-std=c++03</code> the execute may probably prints a zero value but I would prefer a non-zero value.</p>
  
  <pre><code>0
  </code></pre>
  
  <p>Possible output using <code>-std=c++11</code></p>
  
  <pre><code>0
  1208617840
  </code></pre>
  
  <p>Another possible output using <code>-std=c++11</code></p>
  
  <pre><code>0
  -201855824
  </code></pre>
  
  <p>But <a href="http://coliru.stacked-crooked.com/a/17caede8dad15fa7" rel="nofollow noreferrer">my more advanced snippet</a> has now zero-values for uninitialized object <code>B{}.a.i</code> :-(</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct A {
    A() {} // user-defined ctor does not initialize i
    int i;
  };
  
  struct B  {
    A a;
  };
  
  int main()
  {
    std::cout &lt;&lt;"-----------"&lt;&lt; __cplusplus &lt;&lt;"-----------" "\n";
    std::cout &lt;&lt;"B().a.i            = "&lt;&lt;         B().a.i &lt;&lt;'\n';
    std::cout &lt;&lt;"B{}.a.i            = "&lt;&lt;         B{}.a.i &lt;&lt;'\n';
  
    int d;
    d = 42;
    std::cout &lt;&lt;"(new(&amp;d) B  )-&gt;a.i = "&lt;&lt; (new(&amp;d) B  )-&gt;a.i &lt;&lt;'\n';
    d = 42;
    std::cout &lt;&lt;"(new(&amp;d) B())-&gt;a.i = "&lt;&lt; (new(&amp;d) B())-&gt;a.i &lt;&lt;'\n';
    d = 42;
    std::cout &lt;&lt;"(new(&amp;d) B{})-&gt;a.i = "&lt;&lt; (new(&amp;d) B{})-&gt;a.i &lt;&lt;'\n';
  }
  </code></pre>
  
  <p>Build/Run output:</p>
  
  <pre><code>&gt; g++ -std=c++03 -Wall -Wextra -pedantic main.cpp &amp;&amp; ./a.out
  -----------199711-----------
  B().a.i            = 0
  (new(&amp;d) B  )-&gt;a.i = 42
  (new(&amp;d) B())-&gt;a.i = 0
  
  &gt; g++ -std=c++11 -Wall -Wextra -pedantic main.cpp &amp;&amp; ./a.out
  -----------201103-----------
  B().a.i            = 0
  B{}.a.i            = 0
  (new(&amp;d) B  )-&gt;a.i = 42
  (new(&amp;d) B())-&gt;a.i = 0
  (new(&amp;d) B{})-&gt;a.i = 0
  
  &gt; g++ -std=c++14 -Wall -Wextra -pedantic main.cpp &amp;&amp; ./a.out
  -----------201402-----------
  B().a.i            = 0
  B{}.a.i            = 0
  (new(&amp;d) B  )-&gt;a.i = 42
  (new(&amp;d) B())-&gt;a.i = 0
  (new(&amp;d) B{})-&gt;a.i = 0
  </code></pre>