Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The obvious thing that could have gone wrong would be if <code>v</code> wasn't aligned properly.</p> <p>But it's allocated dynamically by <code>vector</code>, so it isn't subject to stack misalignment issues. </p> <p>However, as <a href="https://stackoverflow.com/questions/5216071/sse-and-c-containers/5216132#5216132">phooji</a> correctly points out, a "template" or "prototype" value is passed to the <code>std::vector</code> constructor which will be copied to all the elements of the vector. It's this parameter of <code>std::vector::vector</code> that will be placed on the stack and may be misaligned.</p> <p>Some compilers have a pragma for controlling stack alignment within a function (basically, the compiler wastes some extra space as needed to get all locals properly aligned).</p> <p>According to the Microsoft documentation, <a href="http://msdn.microsoft.com/en-us/library/k1a8ss06.aspx" rel="nofollow noreferrer">Visual C++ 2010 should set up 8 byte stack alignment automatically for SSE types</a> and <a href="http://msdn.microsoft.com/en-us/library/aa290049.aspx" rel="nofollow noreferrer">has done so since Visual C++ 2003</a></p> <p>For gcc I don't know.</p> <hr> <p>Under C++0x, for <code>new point()</code> to return unaligned storage is a serious non-compliance. <code>[basic.stc.dynamic.allocation]</code> says (wording from draft n3225):</p> <blockquote> <p>The allocation function attempts to allocate the requested amount of storage. If it is successful, it shall return the address of the start of a block of storage whose length in bytes shall be at least as large as the requested size. There are no constraints on the contents of the allocated storage on return from the allocation function. The order, contiguity, and initial value of storage allocated by successive calls to an allocation function are unspecified. The pointer returned shall be suitably aligned so that it can be converted to a pointer of any complete object type with a fundamental alignment requirement (3.11) and then used to access the object or array in the storage allocated (until the storage is explicitly deallocated by a call to a corresponding deallocation function).</p> </blockquote> <p>And <code>[basic.align]</code> says:</p> <blockquote> <p>Additionally, a request for runtime allocation of dynamic storage for which the requested alignment cannot be honored shall be treated as an allocation failure.</p> </blockquote> <p>Can you try a newer version of gcc where this might be fixed?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload