Are struct padding bytes preserved by member assignment?
<p>Sample code:</p>

<pre><code>#include &lt;assert.h&gt;

struct S
{
    unsigned char ch;
    int i;
};

int main()
{
    struct S s;

    memset(&amp;s, 0, sizeof s);

    s.ch = 257; 

    assert( 0 == ((unsigned char *)&amp;s)[1] );
}
</code></pre>

<p>Can the assertion fail?</p>

<p>The motivation for the question is whether a compiler on a little-endian system could decide to use a 4-byte store to implement <code>s.ch = 257;</code>.  Obviously nobody would ever write code like I did in my example, but something similar might realistically occur if <code>ch</code> is assigned in various ways in a program which then goes on to use <code>memcmp</code> to check for struct equality.  </p>

<p>For example, if the code does <code>--s.ch</code> instead of <code>s.ch = 257</code> - can the compiler emit a word-size decrement instruction?</p>

<p>I don't think the discussion around <a href="https://stackoverflow.com/questions/33393569/is-it-undefined-behaviour-to-memcpy-from-an-uninitialized-variable/33394724#33394724">DR 451</a> is relevant, as that only applies to uninitialized padding; however the <code>memset</code> initializes all the padding to zero bytes.</p>