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