fork download
  1. #include <stdio.h>
  2.  
  3. typedef unsigned long int uint32_t;
  4.  
  5. typedef union {
  6. struct
  7. {
  8. unsigned char bit1 : 1;
  9. unsigned char bit2 : 1;
  10. unsigned char two_bits : 2;
  11. unsigned char four_bits : 4;
  12. };
  13. uint32_t raw;
  14. } Test;
  15.  
  16. int main(void) {
  17. Test test;
  18. printf( "Sizeof( test ) : %d\n", sizeof(test) );
  19. test.raw = 0;
  20. printf( "Raw : %d\n", test.raw );
  21. test.bit1 = 1;
  22. test.two_bits = 2;
  23. printf( "Raw : %d\n", test.raw );
  24. return 0;
  25. }
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
Sizeof( test ) : 4
Raw : 0
Raw : 9