Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-2455.c
blobd5011a10c2a550222ac9f610bb193ea3c01b7250
1 /*
2 bug-2455.c
3 */
5 #include <testfwk.h>
7 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // pdk needs function pointer to be reentrant even for a single argument
8 typedef int (*funcType) (int);
10 int foo0 (int a)
12 return a + 2;
15 int foo1 (int a)
17 return a - 6;
20 int foo2 (int a)
22 return a * 2;
25 struct
27 funcType fpa[2];
28 funcType fpb;
29 } testS = {{foo0, foo1}, foo2};
30 #endif
32 void testBug (void)
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);
39 testS.fpa[0] = foo1;
40 testS.fpa[1] = foo2;
41 testS.fpb = foo0;
43 ASSERT (testS.fpa[0] (5) == -1);
44 ASSERT (testS.fpa[1] (9) == 18);
45 ASSERT (testS.fpb (5) == 7);
47 testS.fpb = testS.fpa[0];
48 testS.fpa[0] = testS.fpa[1];
49 testS.fpa[1] = foo0;
51 ASSERT (testS.fpa[0] (5) == 10);
52 ASSERT (testS.fpa[1] (9) == 11);
53 ASSERT (testS.fpb (5) == -1);
54 #endif