Consider the following two struct
:
struct a
{
int a;
};
struct b
{
struct a a_struct;
int b;
};
the following instantiation of struct b
:
struct b b_struct;
and this condition:
if (&b_struct == (struct b*)&b_struct.a_struct)
printf("Yes\n");
Does the C standard mandate this to always evaluate true?
Yes, according to 6.7.2.1, "Within a structure object, the non-bit-field members and the units in which bit-fields reside have addresses that increase in the order in which they are declared. A pointer to a structure object, suitably converted, points to its initial member (or if that member is a bit-field, then to the unit in which it resides), and vice versa. There may be unnamed padding within a structure object, but not at its beginning."
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