c - sizeof struct inside struct -
struct s1 { char c; int i; }; struct s3 { char c1; struct s1 s; double c2; };
i trying calculate sizeof(s3)
, program 24. don't know offset of struct s1 inside s3, there rule offset? thought "the offset of s1 must n times of size of itself, i.e., n * sizeof(s1)", however, found not true. help.
the c
standard intentionally flexible on this.
all guarantees (i) address of first element in struct
same address of struct
, , (ii) data members appear in order declared in struct
. (iii) empty struct
have non-zero sizeof
. last 1 means pointer arithmetic valid on null structures.
in particular, padding (of amount) allowed inserted between structure member, , @ end.
Comments
Post a Comment