95f32682691f0b1ccf0af1b1f39747f85c37332c
[fw/sdcc] / 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 #if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80) || defined(SDCC_hc08)
8 #  define code
9 #endif
10
11 void *p;
12 int ret;
13
14 int mul2 (int i)
15 {
16   return 2 * i;
17 }
18
19 void g (int (*h) (int))
20 {
21   ret = h (2);
22 }
23
24 void f1()
25 {
26   p = (void *) mul2;
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 }