scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit ba2ad29b2bf580b5b6318289488b1b18bfd81cc4
parent 618d3316287444bf57deb532c9d105f7049335cf
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  7 Sep 2015 19:01:59 +0200

Basic test for character constants

Diffstat:
Mcc1/lex.c | 7+++++--
Acc1/tests/test021.c | 43+++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/cc1/lex.c b/cc1/lex.c @@ -351,7 +351,7 @@ escape(void) return ' '; } errno = 0; - c = strtoul(input->p, &input->p, base); + c = strtoul(++input->p, &input->p, base); if (errno || c > 255) warn("character constant out of range"); return c; @@ -365,9 +365,12 @@ character(void) if ((c = *++input->p) == '\\') c = escape(); + else + c = *input->p++; if (*input->p != '\'') error("invalid character constant"); - ++input->p; + else + ++input->p; sym = newsym(NS_IDEN); sym->u.i = c; diff --git a/cc1/tests/test021.c b/cc1/tests/test021.c @@ -0,0 +1,43 @@ + +/* +name: TEST021 +description: Basic test for char constants +comments: This test is done for z80 implementation +output: +F1 +G1 F1 main +{ +- +A2 M uc +A3 C sc + A2 #MFF :M + A2 #M23 :M + A2 #M1 :M + A2 #M1 :M + A2 #M41 :M + A3 #CFF :C + A3 #C23 :C + A3 #C1 :C + A3 #C1 :C + A3 #C41 :C +} +*/ + +int +main(void) +{ + unsigned char uc; + signed char sc; + + uc = -1; + uc = '\x23'; + uc = 1u; + uc = 1025; + uc = 'A'; + + sc = -1; + sc = '\x23'; + sc = 1u; + sc = 1025; + sc = 'A'; +}