#include <stdio.h>
#include <string.h>
/*
* Abbreviation:
* NAV - Native Alignment Value
* NAV-of-basic_type: (on 32bit CPU)
* char - 1
* int - 4
* short - 2
* long - 4
* float - 4
* double - 8
* NAV-of-struct: max(NAV-of-members)
* SAV - Specified Alignment Value
* EAV - Effective Alignment Value; EAV = min(NAV, SAV)
* sizeof(struct) % EAV-of-struct == 0
*/
/* default SAV = 4 gcc*/
struct S0_1 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
short s; /* NAV = 2; EAV = min(NAV, SA V) = 2 */
}; /* NAV = max(NAV-of-members) = 2; EAV = min(NAV, SAV) = 2 */
/*
* memory structure:
* 0xbffff380: 0x11 0x00 0x22 0x22
*
* sizeof(struct S0_1) = 4
*/
struct S0_2 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
char c2; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
short s; /* NAV = 2; EAV = min(NAV, SAV) = 2 */
}; /* NAV = max(NAV-of-members) = 2; EAV = min(NAV, SAV) = 2 */
/*
* memory structure:
* 0xbffff37c: 0x11 0x22 0x33 0x33
*
* sizeof(struct S0_2) = 4
*/
struct S0_3 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
char a[2]; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
short s; /* NAV = 2; EAV = min(NAV, SAV) = 2 */
}; /* NAV = max(NAV-of-members) = 2; EAV = min(NAV, SAV) = 2 */
/*
* memory structure:
* 0xbffff376: 0x11 0x22 0x33 0x00 0x44 0x44
*
* sizeof(struct S0_3) = 6
*/
struct S0_4 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
long l; /* NAV = 4; EAV = min(NAV, SAV) = 4 */
}; /* NAV = max(NAV-of-members) = 4; EAV = min(NAV, SAV) = 4 */
/*
* memory structure:
* 0xbffff358: 0x11 0x00 0x00 0x00 0x22 0x22 0x22 0x22
*
* sizeof(struct S0_4) = 8
*/
struct S0_5 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
double d; /* NAV = 8; EAV = min(NAV, SAV) = 4 */
}; /* NAV = max(NAV-of-members) = 8; EAV = min(NAV, SAV) = 4 */
/*
* memory structure:
* 0xbffff344: 0x11 0x00 0x00 0x00 0x22 0x22 0x22 0x22
* 0xbffff34c: 0x22 0x22 0x22 0x22
*
* sizeof(struct S0_5) = 12
*/
struct S {
struct S0_1 m1; /* NAV = 2; EAV = 2; sizeof(struct S0_1) = 4 */
struct S0_2 m2; /* NAV = 2; EAV = 2; sizeof(struct S0_2) = 4 */
struct S0_3 m3; /* NAV = 2; EAV = 2; sizeof(struct S0_3) = 6 */
struct S0_4 m4; /* NAV = 4; EAV = 4; sizeof(struct S0_4) = 8 */
struct S0_5 m5; /* NAV = 8; EAV = 4; sizeof(struct S0_5) = 12 */
}; /* NAV = max(NAV-of-members) = 8; EAV = min(NAV, SAV) = 4 */
/*
* memory structure:
* 0xbffff314: 0x11 0x00 0x22 0x22 0x11 0x22 0x33 0x33
* 0xbffff31c: 0x11 0x22 0x33 0x00 0x44 0x44 0x00 0x00
* 0xbffff324: 0x11 0x00 0x00 0x00 0x22 0x22 0x22 0x22
* 0xbffff32c: 0x11 0x00 0x00 0x00 0x22 0x22 0x22 0x22
* 0xbffff334: 0x22 0x22 0x22 0x22
*
* sizeof(struct S) = 36
*/
#pragma pack(push)
#pragma pack(1) /* SAV = 1 (1 byte alignment) */
struct S1 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
long l; /* NAV = 4; EAV = min(NAV, SAV) = 1 */
short s; /* NAV = 2; EAV = min(NAV, SAV) = 1 */
}; /* NAV = max(NAV-of-members) = 1; EAV = min(NAV, SAV) = 1 */
/*
* memory structure:
* 0xbffff36f: 0x11 0x22 0x22 0x22 0x22 0x33 0x33
*
* sizeof(struct S1) = 7
*/
#pragma pack(pop)
#pragma pack(push)
#pragma pack(2) /* SAV = 2 (2 bytes alignment) */
struct S2 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
long l; /* NAV = 4; EAV = min(NAV, SAV) = 2 */
short s; /* NAV = 2; EAV = min(NAV, SAV) = 2 */
}; /* NAV = max(NAV-of-members) = 2; EAV = min(NAV, SAV) = 2 */
/*
* memory structure:
* 0xbffff350: 0x11 0x00 0x22 0x22 0x22 0x22 0x33 0x33
*
* sizeof(struct S2) = 8
*/
#pragma pack(pop)
/* now, restore 4-bytes alignment, SAV = 4 */
struct S4 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
long l; /* NAV = 4; EAV = min(NAV, SAV) = 4 */
short s; /* NAV = 2; EAV = min(NAV, SAV) = 2 */
}; /* NAV = max(NAV-of-members) = 4; EAV = min(NAV, SAV) = 4 */
/*
* memory structure:
* 0xbffff338: 0x11 0x00 0x00 0x00 0x22 0x22 0x22 0x22
* 0xbffff340: 0x33 0x33 0x00 0x00
*
* sizeof(struct S2) = 12
*/
#include <string.h>
/*
* Abbreviation:
* NAV - Native Alignment Value
* NAV-of-basic_type: (on 32bit CPU)
* char - 1
* int - 4
* short - 2
* long - 4
* float - 4
* double - 8
* NAV-of-struct: max(NAV-of-members)
* SAV - Specified Alignment Value
* EAV - Effective Alignment Value; EAV = min(NAV, SAV)
* sizeof(struct) % EAV-of-struct == 0
*/
/* default SAV = 4 gcc*/
struct S0_1 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
short s; /* NAV = 2; EAV = min(NAV, SA V) = 2 */
}; /* NAV = max(NAV-of-members) = 2; EAV = min(NAV, SAV) = 2 */
/*
* memory structure:
* 0xbffff380: 0x11 0x00 0x22 0x22
*
* sizeof(struct S0_1) = 4
*/
struct S0_2 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
char c2; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
short s; /* NAV = 2; EAV = min(NAV, SAV) = 2 */
}; /* NAV = max(NAV-of-members) = 2; EAV = min(NAV, SAV) = 2 */
/*
* memory structure:
* 0xbffff37c: 0x11 0x22 0x33 0x33
*
* sizeof(struct S0_2) = 4
*/
struct S0_3 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
char a[2]; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
short s; /* NAV = 2; EAV = min(NAV, SAV) = 2 */
}; /* NAV = max(NAV-of-members) = 2; EAV = min(NAV, SAV) = 2 */
/*
* memory structure:
* 0xbffff376: 0x11 0x22 0x33 0x00 0x44 0x44
*
* sizeof(struct S0_3) = 6
*/
struct S0_4 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
long l; /* NAV = 4; EAV = min(NAV, SAV) = 4 */
}; /* NAV = max(NAV-of-members) = 4; EAV = min(NAV, SAV) = 4 */
/*
* memory structure:
* 0xbffff358: 0x11 0x00 0x00 0x00 0x22 0x22 0x22 0x22
*
* sizeof(struct S0_4) = 8
*/
struct S0_5 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
double d; /* NAV = 8; EAV = min(NAV, SAV) = 4 */
}; /* NAV = max(NAV-of-members) = 8; EAV = min(NAV, SAV) = 4 */
/*
* memory structure:
* 0xbffff344: 0x11 0x00 0x00 0x00 0x22 0x22 0x22 0x22
* 0xbffff34c: 0x22 0x22 0x22 0x22
*
* sizeof(struct S0_5) = 12
*/
struct S {
struct S0_1 m1; /* NAV = 2; EAV = 2; sizeof(struct S0_1) = 4 */
struct S0_2 m2; /* NAV = 2; EAV = 2; sizeof(struct S0_2) = 4 */
struct S0_3 m3; /* NAV = 2; EAV = 2; sizeof(struct S0_3) = 6 */
struct S0_4 m4; /* NAV = 4; EAV = 4; sizeof(struct S0_4) = 8 */
struct S0_5 m5; /* NAV = 8; EAV = 4; sizeof(struct S0_5) = 12 */
}; /* NAV = max(NAV-of-members) = 8; EAV = min(NAV, SAV) = 4 */
/*
* memory structure:
* 0xbffff314: 0x11 0x00 0x22 0x22 0x11 0x22 0x33 0x33
* 0xbffff31c: 0x11 0x22 0x33 0x00 0x44 0x44 0x00 0x00
* 0xbffff324: 0x11 0x00 0x00 0x00 0x22 0x22 0x22 0x22
* 0xbffff32c: 0x11 0x00 0x00 0x00 0x22 0x22 0x22 0x22
* 0xbffff334: 0x22 0x22 0x22 0x22
*
* sizeof(struct S) = 36
*/
#pragma pack(push)
#pragma pack(1) /* SAV = 1 (1 byte alignment) */
struct S1 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
long l; /* NAV = 4; EAV = min(NAV, SAV) = 1 */
short s; /* NAV = 2; EAV = min(NAV, SAV) = 1 */
}; /* NAV = max(NAV-of-members) = 1; EAV = min(NAV, SAV) = 1 */
/*
* memory structure:
* 0xbffff36f: 0x11 0x22 0x22 0x22 0x22 0x33 0x33
*
* sizeof(struct S1) = 7
*/
#pragma pack(pop)
#pragma pack(push)
#pragma pack(2) /* SAV = 2 (2 bytes alignment) */
struct S2 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
long l; /* NAV = 4; EAV = min(NAV, SAV) = 2 */
short s; /* NAV = 2; EAV = min(NAV, SAV) = 2 */
}; /* NAV = max(NAV-of-members) = 2; EAV = min(NAV, SAV) = 2 */
/*
* memory structure:
* 0xbffff350: 0x11 0x00 0x22 0x22 0x22 0x22 0x33 0x33
*
* sizeof(struct S2) = 8
*/
#pragma pack(pop)
/* now, restore 4-bytes alignment, SAV = 4 */
struct S4 {
char c; /* NAV = 1; EAV = min(NAV, SAV) = 1 */
long l; /* NAV = 4; EAV = min(NAV, SAV) = 4 */
short s; /* NAV = 2; EAV = min(NAV, SAV) = 2 */
}; /* NAV = max(NAV-of-members) = 4; EAV = min(NAV, SAV) = 4 */
/*
* memory structure:
* 0xbffff338: 0x11 0x00 0x00 0x00 0x22 0x22 0x22 0x22
* 0xbffff340: 0x33 0x33 0x00 0x00
*
* sizeof(struct S2) = 12
*/