title: force g++ to zero initialize memory
body: <p>I want to write some unit tests of a library I'm writing </p>
  
  <p>I have a class which looks like this one : </p>
  
  <pre><code>class A
  {
  public:
      A(B* pB)
      // construction details, involves my library
      // but ultimately there is a new being done ,)
  
      B* m_pB;
  };
  </code></pre>
  
  <p>I'd like to check that the pointer m_pB is actually initialized, so I did something along these lines :</p>
  
  <pre><code>A* p = // creation of this object involves my library
  BOOST_REQUIRE( p-&gt;m_pB != NULL );
  </code></pre>
  
  <p>but it happens g++ does not zero-initialize the memory, so the value of <code>p-&gt;m_pB</code> is just plain random. Is there a way to force g++ to zero initialize this memory for me when I <code>new</code> the object?</p>
  
  <p>I believe Visual Studio does something similar with specific codes dependeing on where the memory is allocated.</p>
  
  <p>edit: I can think of 2 backup solutions right now: using a smart pointer, or writing a new operator ...</p>