Skip to content

Instantly share code, notes, and snippets.

@maluta
Created March 3, 2010 01:22
Show Gist options
  • Save maluta/320194 to your computer and use it in GitHub Desktop.
Save maluta/320194 to your computer and use it in GitHub Desktop.
struct Struct1 {
unsigned int a0;
unsigned int a1;
unsigned int a2;
unsigned int a3;
};
struct Struct2 {
unsigned int a0 : 1;
unsigned int a1 : 1;
unsigned int a2 : 2;
unsigned int a3 : 4;
};
struct Struct3 {
unsigned int a0 : 1;
unsigned int a1 : 1;
unsigned int a2 : 2;
unsigned int a3 : 4;
} __attribute__((__packed__));
int main(int argc, char *argv[]) {
struct Struct1 a; /* sizeof(a) = 16 bytes */
struct Struct2 b; /* sizeof(b) = 4 bytes */
struct Struct3 c; /* sizeof(c) = 1 byte */
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment