shithub: scc

Download patch

ref: db2ea6a2cd2633a66d50471fc91181daff7db230
parent: 6948a02f5fe8c3fea01ec49f314e68b6557e39e6
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Jul 5 13:03:50 EDT 2013

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.

--- a/cc.h
+++ b/cc.h
@@ -13,6 +13,7 @@
 	unsigned char c99;
 	unsigned char useless;
 	unsigned char repeat;
+	unsigned char charsign;
 };
 
 extern  struct user_opt options;
--- a/decl.c
+++ b/decl.c
@@ -109,11 +109,24 @@
 			}
 			/* 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;
 		}
 	}
--