Which of the following are true in Standard C?
(A) The sizeof
a structure is equal to:
the relative address of its last member plus the
sizeof
its last member. (I know this cannot be true.)the relative address of its last member plus the alignment value (as obtained by the
_Alignof
operator) of its last member. (This cannot be true also, because there are cases where thesizeof
a type may be larger than its_Alignof
value. Seelong double
in 32 bit Windows GCC:sizeof
is 12,_Alignof
is 4.)the relative address of its last member plus the alignment value of the structure itself. (This cannot be true also, as explained in the previous statement.)
the relative address of its last member plus the maximum of the last member's size and the alignment value of the structure itself.
something else.
By relative address I mean the distance between the starting byte of its last member and the starting byte of its first member (or the structure itself) which can be obtained with the offsetof
macro like this: offsetof(struct st, last_member)
.
(B) The _Alignof
value of a structure is equal to:
the
_Alignof
value of its member with the largest_Alignof
value.something else.
Notes:
I am not talking about specific implementations on specific environments, but rather how a "Stardard C (C18)"-compliant implementation should behave theoretically.
_Alignof
is the standard C operator andalignof
is its macro synonym defined instdalign.h
header.