title: Is there any guarantee of alignment of address return by C++'s new operation?
body: <p>Most of experienced programmer knows data alignment is important for program's performance. I have seen some programmer wrote program that allocate bigger size of buffer than they need, and use the aligned pointer as begin. I am wondering should I do that in my program, I have no idea is there any guarantee of alignment of address returned by C++'s new operation. So I wrote a little program to test</p>
  
  <pre><code>for(size_t i = 0; i &lt; 100; ++i) {
      char *p = new char[123];
      if(reinterpret_cast&lt;size_t&gt;(p) % 4) {
          cout &lt;&lt; "*";
          system("pause");
      }
      cout &lt;&lt; reinterpret_cast&lt;void *&gt;(p) &lt;&lt; endl;
  }
  for(size_t i = 0; i &lt; 100; ++i) {
      short *p = new short[123];
      if(reinterpret_cast&lt;size_t&gt;(p) % 4) {
          cout &lt;&lt; "*";
          system("pause");
      }
      cout &lt;&lt; reinterpret_cast&lt;void *&gt;(p) &lt;&lt; endl;
  }
  for(size_t i = 0; i &lt; 100; ++i) {
      float *p = new float[123];
      if(reinterpret_cast&lt;size_t&gt;(p) % 4) {
          cout &lt;&lt; "*";
          system("pause");
      }
      cout &lt;&lt; reinterpret_cast&lt;void *&gt;(p) &lt;&lt; endl;
  }
  system("pause");
  </code></pre>
  
  <p>The compiler I am using is Visual C++ Express 2008. It seems that all addresses the new operation returned are aligned. But I am not sure. So my question is: are there any guarantee? If they do have guarantee, I don't have to align myself, if not, I have to.</p>