commit db2ea6a2cd2633a66d50471fc91181daff7db230
parent 6948a02f5fe8c3fea01ec49f314e68b6557e39e6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 5 Jul 2013 17:03:50 +0200
Add option for signed characters
ansi c says that is implementation defined the signess of characters,
and since we have addede a c_sign bit in ctype, it is not a bad idea
adding a flag which allows to the user defines the signess of characters.
This patch also fixes the problem of filling c_sign in other integers
cases.
Diffstat:
2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/cc.h b/cc.h
@@ -13,6 +13,7 @@ struct user_opt {
unsigned char c99;
unsigned char useless;
unsigned char repeat;
+ unsigned char charsign;
};
extern struct user_opt options;
diff --git a/decl.c b/decl.c
@@ -109,11 +109,24 @@ spec(void)
}
/* it is not a type name */
default:
- if (!tp || tp->type)
- return tp;
- warning_error(options.implicit,
- "type defaults to 'int' in declaration");
- tp->type = INT;
+ if (!tp)
+ return NULL;
+ if (!tp->type) {
+ warning_error(options.implicit,
+ "type defaults to 'int' in declaration");
+ tp->type = INT;
+ }
+ if (!tp->c_signed && !tp->c_unsigned) {
+ switch (tp->type) {
+ case CHAR:
+ if (!options.charsign) {
+ tp->c_unsigned = 1;
+ break;
+ }
+ case INT: case SHORT: case LONG: case LLONG:
+ tp->c_signed = 1;
+ }
+ }
return tp;
}
}