Given
struct S {
SomeType single_element_in_the_struct;
};
Is it always true that
sizeof(struct S) == sizeof(SomeType)
Or it may be implementation dependent?
This will usually be the case, but it's not guaranteed.
Any struct may have unnamed padding bytes at the end of the struct, but these are usually used for alignment purposes, which isn't a concern if you only have a single element.
It does not have to be equal, due to structure padding.
section 6.7.2.1 in the C99 standard states that "There may be unnamed padding within a structure object, but not at its beginning".
This is refered to as structure padding. Paddings may be added to make sure that the structure is properly aligned in memory. The exakt size of a structure can change if you change the order of its members.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With