scc

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

commit 4c4c232a9f307952470065c30c82048decb8c6fd
parent 4deece51bfadf521d8509a1bb62531f9937719ab
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 22 Apr 2014 16:24:32 +0200

Separate char and signed/unsigned char

They are different types, and this small difference can
be important if you make a pointer from them, because
in this case the pointers are not equivalent between them.

Diffstat:
Mtypes.c | 37+++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/types.c b/types.c @@ -23,6 +23,12 @@ Type .defined = 1, .u.rank = RANK_BOOL }, + *schartype = &(Type) { + .op = INT, + .letter = 'C', + .defined = 1, + .u.rank = RANK_SCHAR + }, *uchartype = &(Type) { .op = INT, .letter = 'M', @@ -32,9 +38,10 @@ Type }, *chartype = &(Type) { .op = INT, - .letter = 'C', + .letter = 'M', + .sign = 1, .defined = 1, - .u.rank = RANK_SCHAR + .u.rank = RANK_UCHAR }, *ushortype = &(Type) { .op = INT, @@ -109,27 +116,25 @@ Type Type * ctype(int8_t type, int8_t sign, int8_t size) { - if (type == CHAR && !sign) - sign = options.charsign; - if (sign == SIGNED) - sign = 0; if (type == DOUBLE) type = FLOAT, size += LONG; switch (type) { - case VOID: return voidtype; - case BOOL: return booltype; - case CHAR: return (sign) ? uchartype : chartype; + case CHAR: if (sign == 0) + return chartype; + return (sign == UNSIGNED) ? uchartype : schartype; + case VOID: return voidtype; + case BOOL: return booltype; case INT: switch (size) { - case 0: return (sign) ? uinttype : inttype; - case SHORT: return (sign) ? ushortype : shortype; - case LONG: return (sign) ? ulongtype : longtype; - case LONG+LONG: return (sign) ? ullongtype : llongtype; + case 0: return (sign == UNSIGNED) ? uinttype : inttype; + case SHORT: return (sign == UNSIGNED) ? ushortype : shortype; + case LONG: return (sign == UNSIGNED) ? ulongtype : longtype; + case LONG+LONG: return (sign == UNSIGNED) ? ullongtype : llongtype; } case FLOAT: switch (size) { - case 0: return floattype; - case LONG: return doubletype; - case LONG+LONG: return ldoubletype; + case 0: return floattype; + case LONG: return doubletype; + case LONG+LONG: return ldoubletype; } } }