comparison run/mini/union5.d @ 1628:c6ef09dfba4d

add mini test set from ldc project
author Moritz Warning <moritzwarning@web.de>
date Mon, 10 Jan 2011 19:47:18 +0100
parents
children
comparison
equal deleted inserted replaced
1627:e1b954780837 1628:c6ef09dfba4d
1 module union5;
2
3 union S
4 {
5 T t;
6 U u;
7 uint i;
8 struct {
9 ushort sl,sh;
10 }
11 }
12
13 struct T
14 {
15 int i;
16 }
17
18 struct U
19 {
20 float f;
21 }
22
23 void main()
24 {
25 S s;
26 assert(s.t.i == 0);
27 assert(s.u.f == 0);
28 s.t.i = -1;
29 assert(s.i == 0xFFFF_FFFF);
30 float f = 3.1415;
31 s.u.f = f;
32 uint pi = *cast(uint*)&f;
33 assert(s.i == pi);
34 assert(s.sl == (pi&0xFFFF));
35 assert(s.sh == (pi>>>16));
36 }