struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-pr34456.c
blob0059e588c7174ddf96920e563cc713039cffe9d5
1 /*
2 pr34456.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 #include <stdlib.h>
13 #if !defined(__SDCC_pdk14) && !defined (__SDCC_pdk15) // Reentrancy
14 int debug (void) { return 1; }
15 int errors;
17 struct s { int elt; int (*compare) (int); };
19 static int
20 compare (const void *x, const void *y) __reentrant
22 const struct s *s1 = x, *s2 = y;
23 int (*compare1) (int);
24 int elt2;
26 compare1 = s1->compare;
27 elt2 = s2->elt;
28 if (elt2 != 0 && debug () && compare1 (s1->elt) != 0)
29 errors++;
30 return compare1 (elt2);
33 int bad_compare (int x) { return -x; }
34 struct s array[2] = { { 1, bad_compare }, { -1, bad_compare } };
35 #endif
37 void
38 testTortureExecute (void)
40 #if !defined(__SDCC_pdk14) && !defined (__SDCC_pdk15)
41 qsort (array, 2, sizeof (struct s), compare);
42 ASSERT (!(errors == 0));
43 #endif