Boost C++ Libraries: Ticket #12235: boost/endian causes reads from unaligned address. https://svn.boost.org/trac10/ticket/12235 <p> Example: </p> <pre class="wiki">#include &lt;boost/endian/arithmetic.hpp&gt; int main() { char __attribute__ ((aligned (4))) buf[20]; boost::endian::native_int32_t * ptr = (boost::endian::native_int32_t *)&amp;buf[1]; return ptr-&gt;value(); } </pre><p> when stepping inside <em>boost::endian::native_int32_t::value()</em> I see the code which is doing actual work: </p> <pre class="wiki"> return *reinterpret_cast&lt;T const *&gt;(bytes); </pre><p> where <em>bytes</em> is argument which corresponds to class member of <em>endian_buffer</em> which declared as: </p> <pre class="wiki"> char m_value[n_bits/8]; </pre><p> In this particular example <em>m_value</em> gets address <em>buf + 1</em> and it is not dividable by four: </p> <pre class="wiki"> (int)ptr-&gt;m_value &amp; 3 == 1 </pre><p> Not all platforms support reading from unaligned address. This behavior is dangerous and possibly can cause crashes on those platforms. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12235 Trac 1.4.3 Andrii Motsok <amotsok@…> Tue, 31 May 2016 07:21:33 GMT component changed; owner set https://svn.boost.org/trac10/ticket/12235#comment:1 https://svn.boost.org/trac10/ticket/12235#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Beman Dawes</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">endian</span> </li> </ul> Ticket Beman Dawes Tue, 31 May 2016 15:39:32 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/12235#comment:2 https://svn.boost.org/trac10/ticket/12235#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> The code you are complaining about is inside this: </p> <table class="wiki"> <tr># if defined(<span class="underline">x86_64</span>) <td> defined(_M_X64) </td><td> defined(<span class="underline">i386) </span></td><td> defined(_M_IX86) </td></tr></table> <blockquote> <p> <em> On x86 (which is little endian), unaligned loads are permitted </em></p> </blockquote> <p> so is only reached on machines which permit unaligned loads. </p> <p> --Beman </p> Ticket