comparison tests/mini/union5.d @ 341:1bb99290e03a trunk

[svn r362] Started merging the old 'test' dir as well as the newer 'tangotests' dir into 'tests/mini' and 'tests/minicomplex'.
author lindquist
date Sun, 13 Jul 2008 02:51:19 +0200
parents test/union5.d@9e1bd80a7e98
children 44f08170f4ef
comparison
equal deleted inserted replaced
340:351c0077d0b3 341:1bb99290e03a
1 module union5;
2
3 pragma(LLVM_internal, "notypeinfo")
4 {
5 union S
6 {
7 T t;
8 U u;
9 uint i;
10 struct {
11 ushort sl,sh;
12 }
13 }
14
15 struct T
16 {
17 int i;
18 }
19
20 struct U
21 {
22 float f;
23 }
24 }
25
26 void main()
27 {
28 S s;
29 assert(s.t.i == 0);
30 assert(s.u.f == 0);
31 s.t.i = -1;
32 assert(s.i == 0xFFFF_FFFF);
33 float f = 3.1415;
34 s.u.f = f;
35 uint pi = *cast(uint*)&f;
36 assert(s.i == pi);
37 assert(s.sl == (pi&0xFFFF));
38 assert(s.sh == (pi>>>16));
39 }