1 module it.c.compile.union_;
2 
3 
4 import it;
5 
6 
7 @("__SIZEOF_PTHREAD_ATTR_T")
8 @safe unittest {
9     shouldCompile(
10         C(
11             `
12                 #ifdef __x86_64__
13                 #  if __WORDSIZE == 64
14                 #    define __SIZEOF_PTHREAD_ATTR_T 56
15                 #  else
16                 #    define __SIZEOF_PTHREAD_ATTR_T 32
17                 #  endif
18                 #else
19                 #  define __SIZEOF_PTHREAD_ATTR_T 36
20                 #endif
21 
22                 union pthread_attr_t
23                 {
24                     char __size[__SIZEOF_PTHREAD_ATTR_T];
25                     long int __align;
26                 };
27             `
28         ),
29 
30         D(
31             q{
32                 pthread_attr_t attr;
33                 attr.__size[0] = 42;
34             }
35         )
36     );
37 }
38 
39 
40 @("immediate union variable declarations")
41 @safe unittest {
42     shouldCompile(
43         C(
44             q{
45                 struct Struct {
46                     union {
47                         int i;
48                         double d;
49                     } var1, var2;
50                 };
51             }
52         ),
53 
54         D(
55             q{
56                 auto s = Struct();
57                 static assert(is(typeof(s.var1.i) == int));
58                 static assert(is(typeof(s.var1.d) == double));
59                 static assert(is(typeof(s.var2.i) == int));
60                 static assert(is(typeof(s.var2.d) == double));
61             }
62         )
63     );
64 }