* src/SDCCval.c, src/SDCCmain.c, device/include/limits.h,
[fw/sdcc] / support / regression / tests / funsigned-char.c
1 /*
2  * check for the correct signness of a char constant
3  *   (signed versus unsigned)
4  *   (indirect via integer promotion)
5  *
6  * Note, the check for the --funsigned-char must be invoked by hand
7  *   see the following emacs sexp
8  *     (compile "SDCCFLAGS=--funsigned-char make -C .. ALL_TESTS='./tests/funsigned-char.c'")
9  *     (compile "make -C .. ALL_TESTS='./tests/funsigned-char.c'")
10  *
11  */
12
13 #include <testfwk.h>
14 #include <stdint.h>
15 #include <limits.h>
16
17 int glb_schar_to_int = ~ (signed char)   '\200';
18 int glb_uchar_to_int = ~ (unsigned char) '\200';
19 int glb_char_to_int  = ~                 '\200';
20
21 int tst_schar_to_int()  { return ~ (signed char)   '\200'; }
22 int tst_uchar_to_int()  { return ~ (unsigned char) '\200'; }
23 int tst_char_to_int()   { return ~                 '\200'; }
24
25
26 void
27 testBug(void)
28 {
29 #ifdef SDCC_CHAR_UNSIGNED
30   ASSERT(CHAR_MAX ==  255);
31   ASSERT(CHAR_MIN ==    0);
32 #else
33   ASSERT(CHAR_MAX ==  127);
34   ASSERT(CHAR_MIN == -128);
35 #endif
36
37   ASSERT(tst_uchar_to_int() == -129);
38   ASSERT(glb_uchar_to_int   == -129);
39
40   ASSERT(tst_schar_to_int() ==  127);
41   ASSERT(glb_schar_to_int   ==  127);
42
43 #ifdef SDCC_CHAR_UNSIGNED
44   ASSERT(tst_char_to_int() == -129);
45   ASSERT(glb_char_to_int   == -129);
46 #else
47   ASSERT(tst_char_to_int() ==  127);
48   ASSERT(glb_char_to_int   ==  127);
49 #endif
50 }