tcc -MD: drop system includes and duplicates
[tinycc.git] / tests / tests2 / 33_ternary_op.c
blob1e6b56d666db0d8efc40f8922e85968160de5aa2
1 #include <assert.h>
2 extern int printf(const char*, ...);
4 char arr[1];
5 static void f (void){}
6 void (*fp)(void) = f;
7 void call_fp()
9 (fp?f:f)();
10 (fp?fp:fp)();
11 (fp?fp:&f)();
12 (fp?&f:fp)();
13 (fp?&f:&f)();
14 _Generic(0?arr:arr, char*: (void)0);
15 _Generic(0?&arr[0]:arr, char*: (void)0);
16 _Generic(0?arr:&arr[0], char*: (void)0);
17 _Generic(1?arr:arr, char*: (void)0);
18 _Generic(1?&arr[0]:arr, char*: (void)0);
19 _Generic(1?arr:&arr[0], char*: (void)0);
20 _Generic((__typeof(1?f:f)*){0}, void (**)(void): (void)0);
21 (fp?&f:f)();
22 (fp?f:&f)();
23 _Generic((__typeof(fp?0L:(void)0)*){0}, void*: (void)0);
25 /* The following line causes a warning */
26 void *xx = fp?f:1;
29 struct condstruct {
30 int i;
33 static int getme(struct condstruct* s, int i)
35 int i1 = (i != 0 ? 0 : s)->i;
36 int i2 = (i == 0 ? s : 0)->i;
37 int i3 = (i != 0 ? (void*)0 : s)->i;
38 int i4 = (i == 0 ? s : (void*)0)->i;
39 return i1 + i2 + i3 + i4;
42 int main()
44 int Count;
46 for (Count = 0; Count < 10; Count++)
48 printf("%d\n", (Count < 5) ? (Count*Count) : (Count * 3));
52 int c = 0;
53 #define ASSERT(X) assert(X)
54 static struct stru { int x; } a={'A'},b={'B'};
55 static const struct stru2 { int x; } d = { 'D' };
56 ASSERT('A'==(*(1?&a:&b)).x);
57 ASSERT('A'==(1?a:b).x);
58 ASSERT('A'==(c?b:a).x);
59 ASSERT('A'==(0?b:a).x);
60 c=1;
61 ASSERT('A'==(c?a:b).x);
62 ASSERT(sizeof(int) == sizeof(0 ? 'a' : c));
63 ASSERT(sizeof(double) == sizeof(0 ? 'a' : 1.0));
64 ASSERT(sizeof(double) == sizeof(0 ? 0.0 : 'a'));
65 ASSERT(sizeof(float) == sizeof(0 ? 'a' : 1.0f));
66 ASSERT(sizeof(double) == sizeof(0 ? 0.0 : 1.0f));
67 struct condstruct cs = { 38 };
68 printf("%d\n", getme(&cs, 0));
70 // the following lines contain type mismatch errors in every ternary expression
71 //printf("comparing double with pointer : size = %d\n", sizeof(0 ? &c : 0.0));
72 //printf("'%c' <> '%c'\n", (0 ? a : d).x, (1 ? a : d).x);
73 //0 ? a : 0.0;
77 return 0;
80 /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/