struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bitvars.c.in
blob34cb8e57c49112ef1d1fd02aade10e18dd108bf2
1 /** Bit vars test.
3 type: bool, char, unsigned char, unsigned short, unsigned long
4 */
6 #include <testfwk.h>
8 #ifdef __SDCC
9 #pragma std_sdcc99
10 #endif
12 #include <limits.h>
13 #include <stdbool.h>
15 #ifndef PORT_HOST
16 #pragma disable_warning 180 //no warning about using complement on bit/unsigned char
17 #endif
19 #ifdef __bool_true_false_are_defined
21 #define TYPE_{type}
23 char foo(bool a, bool b, char c)
25 return a + b + c;
28 char complement(bool a, bool b)
30 return (a == b);
33 {type} _0 = 0, _1 = 1, _ff = 0xFF, _ffff = -1;
35 #endif //__bool_true_false_are_defined
37 void
38 testBits(void)
40 #ifndef __SDCC_pic16
41 #ifdef __bool_true_false_are_defined
42 bool x = 2;
43 ASSERT (foo(x,3,4) == 6);
45 ASSERT (complement (~_0, 1));
46 ASSERT (complement (~_1, 1));
48 #if !(defined(__SUNPRO_C) && defined(__i386))
49 /* this test fails on Solaris i386 SunPro C compiler with -xO2 option;
50 it pass without -xO2 option !? */
51 #if defined TYPE_char && CHAR_MIN < 0
52 ASSERT (complement (~_ff, 0));
53 #else
54 ASSERT (complement (~_ff, 1));
55 #endif
56 #endif
58 #if defined TYPE_bool
59 ASSERT (complement (~_ffff, 1));
60 #elif defined TYPE_char && CHAR_MIN < 0
61 ASSERT (complement (~_ffff, 0));
62 #else
63 if (sizeof({type}) < sizeof(int))
64 ASSERT (complement (~_ffff, 1));
65 else
66 ASSERT (complement (~_ffff, 0));
67 #endif
69 #endif //__bool_true_false_are_defined
70 #endif