Imported Upstream version 2.9.0
[debian/cc1111] / support / regression / tests / bug-716242.c
1 /* bug-716242.c
2
3    syntax tests about function pointers at compile time
4  */
5 #include <testfwk.h>
6
7 void *p;
8 int ret;
9
10 int mul2 (int i)
11 {
12   return 2 * i;
13 }
14
15 void g (int (*h) (int))
16 {
17   ret = h (2);
18 }
19
20 void f1()
21 {
22 #if defined(SDCC_ds390)
23   p = (void code *) mul2;
24 #else
25   p = (void *) mul2;
26 #endif
27   g ((int (*) (int)) p);
28 }
29
30 /****************************/
31
32 void g (int (*h) (int));
33
34 void f2()
35 {
36   int (*fp) (int) = p;
37
38   g (fp);
39 }
40
41 /****************************/
42
43 void g (int (*h) (int));
44
45 void f3()
46 {
47   int (*fp) (int) = (int (*) (int)) p;
48
49   g (fp);
50 }
51
52 /****************************/
53
54 void f4()
55 {
56   ((void (code *) (void)) p) ();
57 }
58
59 /****************************/
60
61 void f5()
62 {
63   int (*fp) (int) = mul2;
64
65   fp(1);
66 }
67
68 /****************************/
69
70 void f6()
71 {
72   ((void (code *) (void)) 0) ();
73 }
74
75 /****************************/
76
77 static void
78 testFuncPtr(void)
79 {
80   f1();
81   ASSERT(ret == 4);
82 }