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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -