Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / funsigned-char.c
blob70223f3a404f2f1719d2e932782c13d4486a3b4e
1 /*
2 * check for the correct signness of a char constant
3 * (signed versus unsigned)
4 * (indirect via integer promotion)
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'")
13 #include <testfwk.h>
14 #include <stdint.h>
15 #include <limits.h>
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';
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'; }
26 void
27 testBug(void)
29 #if CHAR_MIN >= 0
30 ASSERT(CHAR_MAX == 255);
31 ASSERT(CHAR_MIN == 0);
32 #else
33 ASSERT(CHAR_MAX == 127);
34 ASSERT(CHAR_MIN == -128);
35 #endif
37 ASSERT(tst_uchar_to_int() == -129);
38 ASSERT(glb_uchar_to_int == -129);
40 ASSERT(tst_schar_to_int() == 127);
41 ASSERT(glb_schar_to_int == 127);
43 #if CHAR_MIN >= 0
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