1 /*
2    bug-2455.c
3 */
4 
5 #include <testfwk.h>
6 
7 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15)
8 typedef int (*funcType) (int);
9 
foo0(int a)10 int foo0 (int a)
11 {
12   return a + 2;
13 }
14 
foo1(int a)15 int foo1 (int a)
16 {
17   return a - 6;
18 }
19 
foo2(int a)20 int foo2 (int a)
21 {
22   return a * 2;
23 }
24 
25 struct
26 {
27   funcType fpa[2];
28   funcType fpb;
29 } testS = {{foo0, foo1}, foo2};
30 #endif
31 
testBug(void)32 void testBug (void)
33 {
34 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15)
35   ASSERT (testS.fpa[0] (5) == 7);
36   ASSERT (testS.fpa[1] (9) == 3);
37   ASSERT (testS.fpb (5) == 10);
38 
39   testS.fpa[0] = foo1;
40   testS.fpa[1] = foo2;
41   testS.fpb = foo0;
42 
43   ASSERT (testS.fpa[0] (5) == -1);
44   ASSERT (testS.fpa[1] (9) == 18);
45   ASSERT (testS.fpb (5) == 7);
46 
47   testS.fpb = testS.fpa[0];
48   testS.fpa[0] = testS.fpa[1];
49   testS.fpa[1] = foo0;
50 
51   ASSERT (testS.fpa[0] (5) == 10);
52   ASSERT (testS.fpa[1] (9) == 11);
53   ASSERT (testS.fpb (5) == -1);
54 #endif
55 }
56