fields.c 676 B

1234567891011121314151617181920212223242526272829303132333435
  1. struct foo {
  2. int a;
  3. char b;
  4. int x : 12, y : 4, : 0, : 4, z : 3;
  5. char c;
  6. } x = { 1, 2, 3, 4, 5, 6 };
  7. int i = 16;
  8. struct baz { unsigned int a:2, b:4, c:32;} y = { 7, 8, 9};
  9. main()
  10. {
  11. printf("x = %d %d %d %d %d %d\n", x.a, x.b, x.x, x.y, x.z, x.c);
  12. printf("y = %d %d %d\n", y.a, y.b, y.c);
  13. x.y = i;
  14. x.z = 070;
  15. printf("x = %d %d %d %d %d %d\n", x.a, x.b, x.x, x.y, x.z, x.c);
  16. y.a = 2;
  17. y.c = i;
  18. printf("y = %d %d %d\n", y.a, y.b, y.c);
  19. f2(&x);
  20. return 0;
  21. }
  22. f1(struct baz *p) {
  23. p->a = p->b = 0;
  24. if (p->b)
  25. printf("p->b != 0!\n");
  26. p->a = 0x3; p->b = 0xf;
  27. printf("p->a = 0x%x, p->b = 0x%x\n", p->a, p->b);
  28. }
  29. f2(struct baz *p) {
  30. p->a = (i==0);
  31. p->b = (f1(p),0);
  32. }