struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / genptrs.c
blob38e0de40cca2555ae650351abbbd8c0ad440982c
1 /* generic pointer comparison
2 */
4 #include <testfwk.h>
5 #include <stdlib.h>
7 #if !((defined __SDCC_stm8) && defined (__SDCC_MODEL_LARGE))
8 #define CAN_ASSIGN_VOID_TO_FPTR 1
9 #pragma disable_warning 244
10 #endif
12 char eq(void * p1, void * p2)
14 return (p1 == p2);
17 char neq(void * p1, void * p2)
19 return (p1 != p2);
22 char smaller(void * p1, void * p2)
24 return (p1 < p2);
27 char greater(void * p1, void * p2)
29 return (p1 > p2);
32 char __xdata * xp0 = NULL;
33 char __xdata * xp1 = (char __xdata *)0x0001;
34 char __idata * ip0 = NULL;
35 char __idata * ip1 = (char __idata *)0x0001;
36 char __pdata * pp0 = NULL;
37 char __pdata * pp1 = (char __pdata *)0x0001;
38 char __code * cp0 = NULL;
39 char __code * cp1 = (char __code *)0x0001;
40 void (* fp0)(void) = NULL;
41 void (* fp1)(void) = (void (*)(void))0x0001;
42 #if defined (__SDCC_MODEL_HUGE)
43 void (* fpE)(void) = (void (*)(void))0x7E8000; //SDCC assumes banked pointers have physical address != 0
44 void (* fpF)(void) = (void (*)(void))0x7F8000; //choose the banks to be mapped to 0x8000 for the test
45 #endif
46 char * gp0 = NULL;
47 char * gp2 = (char __pdata *)0x0002;
49 void testPtrs(void)
51 #ifndef __SDCC_pic16
52 #if defined (__SDCC_MODEL_HUGE)
53 char __code * cp2 = (char __code *)0x0002;
54 void (* fp2)(void) = (void (*)(void))0x0002;
56 ASSERT (eq(cp2, fp2));
57 ASSERT (smaller(fpE, fpF));
58 #endif
60 ASSERT (xp0 == NULL);
61 ASSERT (ip0 == NULL);
62 ASSERT (pp0 == NULL);
63 ASSERT (cp0 == NULL);
64 ASSERT (fp0 == NULL);
65 ASSERT (gp0 == NULL);
67 ASSERT (xp1 != NULL);
68 ASSERT (ip1 != NULL);
69 ASSERT (pp1 != NULL);
70 ASSERT (cp1 != NULL);
71 ASSERT (fp1 != NULL);
72 ASSERT (gp2 != NULL);
74 ASSERT (eq(xp0, ip0));
75 ASSERT (eq(xp0, pp0));
76 ASSERT (eq(xp0, cp0));
77 #ifdef CAN_ASSIGN_VOID_TO_FPTR
78 ASSERT (eq(xp0, fp0));
79 #endif
80 ASSERT (eq(xp0, gp0));
82 #if defined(__SDCC_mcs51) || defined(__SDCC_ds390)
83 ASSERT (neq(xp1, ip1));
84 ASSERT (neq(xp1, pp1));
85 ASSERT (neq(xp1, cp1));
86 ASSERT (neq(xp1, fp1));
87 ASSERT (neq(xp1, gp2));
89 ASSERT (smaller(xp1, ip1) || greater(xp1, ip1));
90 ASSERT (smaller(xp1, pp1) || greater(xp1, pp1));
91 ASSERT (smaller(xp1, cp1) || greater(xp1, cp1));
92 ASSERT (smaller(xp1, fp1) || greater(xp1, fp1));
93 ASSERT (smaller(xp1, gp2) || greater(xp1, gp2));
95 ASSERT (!smaller(xp0, ip0) && !greater(xp0, ip0));
96 ASSERT (!smaller(xp0, pp0) && !greater(xp0, pp0));
97 ASSERT (!smaller(xp0, cp0) && !greater(xp0, cp0));
98 ASSERT (!smaller(xp0, fp0) && !greater(xp0, fp0));
99 ASSERT (!smaller(xp0, gp0) && !greater(xp0, gp0));
100 #endif
101 #ifdef CAN_ASSIGN_VOID_TO_FPTR
102 ASSERT (eq(cp1, fp1));
103 #endif
104 ASSERT (smaller(pp1, gp2));
105 #endif