Boost C++ Libraries: Ticket #13614: padding related issue on VS2017 with boost::endian https://svn.boost.org/trac10/ticket/13614 <p> On Visual Studio 2017 upd3, there seems to be some unexpected padding-related behaviour, shown below. The issue might not necessarily be a library 'bug', but I think it's worth looking at. </p> <div class="wikipage" style="font-size: 80%"><p> Code highlighting: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;stdio.h&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/endian/arithmetic.hpp&gt;</span><span class="cp"></span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">boost</span><span class="o">::</span><span class="n">endian</span><span class="p">;</span> <span class="cp">#pragma pack(push, 1)</span> <span class="k">struct</span> <span class="n">Empty</span> <span class="p">{};</span> <span class="k">struct</span> <span class="n">T1</span> <span class="p">{</span> <span class="n">big_uint16_t</span> <span class="n">d</span><span class="p">;</span> <span class="kt">uint8_t</span> <span class="n">d2</span><span class="p">;</span> <span class="p">};</span> <span class="k">struct</span> <span class="n">T2</span> <span class="p">{</span> <span class="kt">uint16_t</span> <span class="n">d</span><span class="p">;</span> <span class="kt">uint8_t</span> <span class="n">d2</span><span class="p">;</span> <span class="p">};</span> <span class="k">struct</span> <span class="nl">D0</span><span class="p">:</span> <span class="n">T1</span> <span class="p">{}</span> <span class="n">x0</span><span class="p">;</span> <span class="c1">// sizeof(x0) evaluates to 3</span> <span class="k">struct</span> <span class="nl">D1</span><span class="p">:</span> <span class="n">T1</span><span class="p">,</span> <span class="n">Empty</span> <span class="p">{}</span> <span class="n">x1</span><span class="p">;</span> <span class="c1">// sizeof(x1) evaluates to 4 &lt;- i think this should also be 3</span> <span class="k">struct</span> <span class="nl">D2</span><span class="p">:</span> <span class="n">T2</span><span class="p">,</span> <span class="n">Empty</span> <span class="p">{}</span> <span class="n">x2</span><span class="p">;</span> <span class="c1">// sizeof(x2) evaluates to 3</span> <span class="c1">// (uint8_t*)&amp;x1.d2 - (uint8_t*)&amp;x1.d evaluates to 2 (i.e. big_uint16_t is itself not padded)</span> <span class="c1">//</span> <span class="c1">// - tested with a struct containing a char[2], this did not happen</span> <span class="c1">// - tested on various versions of g++ and clang, but this did not happen either.</span> <span class="cp">#pragma pack(pop)</span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%zu %zu %zu&quot;</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">x0</span><span class="p">),</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">x1</span><span class="p">),</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">x2</span><span class="p">));</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13614 Trac 1.4.3