Skip to content

Instantly share code, notes, and snippets.

@khajavi
Created May 29, 2013 03:15
Show Gist options
  • Save khajavi/5667737 to your computer and use it in GitHub Desktop.
Save khajavi/5667737 to your computer and use it in GitHub Desktop.
example of bitfield in c programming.
#include <stdio.h>
struct Bitfield {
int a:4;
unsigned int b:4;
} bit;
struct Boolean {
unsigned int a:1;
} boolean;
struct A {
unsigned int a:16;
unsigned int b:16;
};
int main() {
bit.a = 12;
printf("a: %d\n", bit.a );
bit.b = 12;
printf("b: %d\n", bit.b);
printf("sizeof(Boolean) is : %d!!!\n", sizeof( boolean ) );
printf("sizeof(A) is : %d!!!\n", sizeof( struct A ) );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment