gcc/
[official-gcc.git] / gcc / testsuite / gcc.dg / fixed-point / union-init.c
blob126cc9e72cf5181710ecd72179cc0e8a557778d4
1 /* { dg-do run } */
2 /* { dg-options "-std=gnu99" } */
4 /* Cast to union is a GNU C extension.
5 Based on the test from ../dfp/. */
7 extern void abort (void);
9 union u
11 long _Fract lf;
12 double d;
15 union n
17 double d;
18 _Fract f;
21 int main ()
23 static union u u1 = { 0.1lr };
24 static union u u2 = { 0.2lr };
25 static union u u4 = { 0.0 };
27 static union n n1 = { 0.3r };
28 static union n n2 = { 3.25 };
30 long _Fract lf;
31 _Fract f;
32 double d;
34 if (u1.lf != 0.1lr)
35 abort ();
37 if (u2.lf != 0.2lr)
38 abort ();
40 /* cast fixed-point to union type. */
41 lf = 0.4lr;
42 f = 0.5r;
43 d = 3.25;
45 u4 = (union u) lf;
46 if (u4.lf != 0.4lr)
47 abort ();
49 u4 = (union u) d;
50 if (u4.d != 3.25)
51 abort ();
53 n1 = (union n) f;
54 if (n1.f != 0.5r)
55 abort ();
57 n1 = (union n)d;
58 if (n1.d != 3.25)
59 abort ();
61 return 0;