aboutsummaryrefslogtreecommitdiff
path: root/SingleSource/UnitTests/2009-04-16-BitfieldInitialization.c
blob: 7124cf84654b7979cada840155b388958f3f3f68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// PR3510 & rdar://6564697

struct ty { 
  int info;
  union {
    int id;
    char *str;
  } u;
} t1  = { 101,  1 };

struct ty2 { 
  float info __attribute__((packed));
  char x;
  int Y __attribute__((packed));
} __attribute__((packed)) t2  = { 101,  1, 204 };

struct ty3 { int A; char C[]; } t3 = { 4, "fo" };

struct ty4 { 
  long double x __attribute__((packed));
  char y;
  long double z __attribute__((packed));
} __attribute__((packed)) t4  = { 1.0,  4, 17.0 };


struct { 
  char x;
  unsigned char y : 4;
} __attribute__((packed)) t5a  = { 101,  15 };

struct { 
  char x;
  unsigned short y : 12;
} __attribute__((packed)) t5b  = { 101,  1231 };

struct { 
  char x;
  unsigned char y : 4;
  unsigned char z : 7;
} __attribute__((packed)) t5  = { 101,  15, 123 };


struct { 
  long double x;
  unsigned char y : 4;
} __attribute__((packed)) t6  = { 123.412,  5 };

struct { 
  char x;
  unsigned char y : 4;
  unsigned char q : 3;
  unsigned char z : 7;
} __attribute__((packed)) t7  = { 101,  15, 123 };


struct { 
  char x;
  unsigned short y : 4;
  unsigned short q : 12;
} __attribute__((packed)) t7a  = { 101,  15, 123 };

struct sDescrItem {
  char what;
  char *types;
  char type;
} t8 = {16, 0, 32};


struct resword {
  const int *a;
  unsigned b : 16;
  int c : 16;
} t9 = { 0, 123, 456 };

// rdar://6861719
#pragma pack(4)

struct t10s {
  short a;
  int *b;
};

#pragma pack()

int x = 42;
struct t10s t10 = { 
.b = &x
};


#include <stdio.h>

int main() {
  printf("1: %d, %d\n", t1.info, t1.u.id);
  printf("2: %f, %d, %d\n", t2.info, t2.x, t2.Y);
  printf("3: %d %s\n", t3.A, t3.C);
  printf("4: %f %d %f\n", (double)t4.x, t4.y, (double)t4.z);
  printf("5: %d %d %d\n", t5.x, t5.y, t5.z);
  printf("5a: %d %d\n", t5a.x, t5a.y);
  printf("5b: %d %d\n", t5b.x, t5b.y);
  printf("6: %Lf %d\n", t6.x, t6.y);
  printf("7: %d %d %d %d\n", t7.x, t7.y, t7.q, t7.z);
  printf("7a: %d %d %d\n", t7a.x, t7a.y, t7a.q);
  printf("8: %d %d\n", t8.what, t8.type);
  printf("9: %d %d\n", t9.b, t9.c);
  printf("10: %d\n", *t10.b);
  return 0;
}