merge from gcc
[external/binutils.git] / gdb / testsuite / gdb.base / complex.c
1 /* Copyright 2002, 2003, 2004, 2007, 2008, 2009, 2010
2 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 /* Test taken from GCC.  Verify that we can print a structure containing
20    a complex number.  */
21
22 #include <stdlib.h>
23
24 typedef __complex__ float cf;
25 struct x { char c; cf f; } __attribute__ ((__packed__));
26 struct unpacked_x { char c; cf f; };
27 extern void f4 (struct unpacked_x*);
28 extern void f3 (void);
29 extern void f2 (struct x*);
30 extern void f1 (void);
31 int
32 main (void)
33 {
34   f1 ();
35   f3 ();
36   exit (0);
37 }
38
39 void
40 f1 (void)
41 {
42   struct x s;
43   s.f = 1;
44   s.c = 42;
45   f2 (&s);
46 }
47
48 void
49 f2 (struct x *y)
50 {
51   if (y->f != 1 || y->c != 42)
52     abort ();
53 }
54
55 void
56 f3 (void)
57 {
58   struct unpacked_x s;
59   s.f = 1;
60   s.c = 42;
61   f4 (&s);
62 }
63
64 void
65 f4 (struct unpacked_x *y)
66 {
67   if (y->f != 1 || y->c != 42)
68     abort ();
69 }