Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / fptr_cast_array_init.c
blobb5e973674c66f20dd8afb0d1a75771fb565b66c4
1 /** Test type cast with function pointers in array initialization.
2 */
4 #include <testfwk.h>
6 #ifdef __SDCC
7 /* don't spam the output with "pointer types incompatible" warnings */
8 #pragma disable_warning 244
9 #endif
11 void a(void) {}
13 typedef void (*fp)(void);
15 void testFptrCastOld(void)
17 /* old functionality */
18 fp tab1[2] = {a, 0};
19 ASSERT(tab1[0] == a);
20 fp tab2[2] = {&a, 0};
21 ASSERT(tab2[0] == a);
22 fp tab3[2] = {(fp)a, 0};
23 ASSERT(tab3[0] == a);
24 fp tab4[2] = {(fp)&a, 0};
25 ASSERT(tab4[0] == a);
26 /* sizeof(void *) < sizeof(fp) implies undefined behavior,
27 * i.e. the result of the comparison does not matter */
28 void * tab5[2] = {a, 0};
29 ASSERT(sizeof(void *) < sizeof(fp) || ((fp)tab5[0]) == a);
30 void * tab6[2] = {&a, 0};
31 ASSERT(sizeof(void *) < sizeof(fp) || ((fp)tab6[0]) == a);
34 void testFptrCastNew(void)
36 /* new functionality */
37 void * tab1[2] = {(void*)a, 0};
38 ASSERT(sizeof(void *) < sizeof(fp) || ((fp)tab1[0]) == a);
39 void * tab2[2] = {(void*)&a, 0};
40 ASSERT(sizeof(void *) < sizeof(fp) || ((fp)tab2[0]) == a);
41 char * tab3[2] = {(char*)a, 0};
42 ASSERT(sizeof(char *) < sizeof(fp) || ((fp)tab3[0]) == a);
43 char * tab4[2] = {(char*)&a, 0};
44 ASSERT(sizeof(char *) < sizeof(fp) || ((fp)tab4[0]) == a);