struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug2084206.c
blob1815256e96ea0bbf7d31fcb07b933d8b98d936ce
1 /*
2 bug 2084206
3 */
5 #include <stdarg.h>
6 #include <testfwk.h>
8 typedef struct {
9 void (*f) (void);
10 char c;
11 char* p;
12 } data_t;
14 typedef void* voidp_t;
15 typedef void (*funp_t)(void);
17 volatile data_t mydata;
19 long varargs(char i, ...)
21 va_list arg;
22 long ret = -1;
24 va_start (arg, i);
25 switch (i)
27 case 1: ret = (long)va_arg(arg, voidp_t); break;
28 case 2: ret = (long)va_arg(arg, funp_t); break;
30 va_end (arg);
31 return ret;
34 void testBug(void)
36 #ifndef __SDCC_pdk14 // Lack of memory - see RFE # 613.
37 #ifndef __SDCC_pdk15 // TODO: Decide on support for casts between object and function pointers for pdk!
38 #ifndef __SDCC_pic16
39 #if !((defined __SDCC_stm8) && defined(__SDCC_MODEL_LARGE)) // STM8 large model has sizeof(void *) < size of function pointers.
40 #if !defined(__SDCC_ds390) && !defined(__SDCC_mcs51) // DS390 and at least some MCS-51 memory models have sizeof(void *) > size of function pointers.
41 void* ptr = testBug;
42 mydata.f = testBug;
43 ASSERT (varargs(1, mydata.f) == (long)ptr);
44 ASSERT (varargs(1, mydata.f) == (long)(void*)testBug);
45 ASSERT (varargs(2, (funp_t)mydata.f) == (long)mydata.f);
46 ASSERT (varargs(2, (void (*)(void))mydata.f) == (long)mydata.f);
47 #endif
48 #endif
49 #endif
50 #endif
51 #endif