Why is there a size mismatch between structures and unions?
<p>I have declared a union allocating 4100 bytes to variable "sample_union" and made the same union declaration as part of a structure which is allocating 4104 bytes.</p>

<pre><code>union test_size_union {
    struct {
        uint8_t type;
        union {
            uint8_t count;
            uint8_t list;
        };
        uint16_t rc;
        uint16_t arr_value[2048];
    };
    uint64_t first_dword;
}__attribute__((packed)) sample_union ;
</code></pre>

<p>Placing the above union inside structure is allocating 4104 bytes.</p>

<pre><code>struct test_size_struct {
    union {
        struct {
            uint8_t type;
            union {
                uint8_t count;
                uint8_t list;
            };
            uint16_t rc;
            uint16_t arr_value[2048];
        };
        uint64_t first_dword;
    };
}__attribute__((packed)) sample_struct;
</code></pre>

<p>Well, this is not a project requirement, but I would like to know why compiler is behaving differently for this two declaration.</p>

<p>gcc version: (GCC) 4.9.2, x86_64</p>

<p>Platform: Linux, x86_64</p>