shithub: scc

Download patch

ref: d3cf9edc145d0c14209dd4bb1339778a5c4436fb
parent: bcc4c2b84232c42faead193fc05879867f7dc7f2
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Oct 5 19:08:01 EDT 2015

Fix definition of macros with -D

A correct macro definition must have the number of
the arguments for this macro, so if we don't add
-1# to the user macro definitions then we can
generate some errors later.

--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -28,11 +28,17 @@
 Symbol *
 defmacro(char *s)
 {
-	char *p;
+	char *p, *q;
 	Symbol *sym;
+	size_t len;
 
-	if ((p = strchr(s, '=')) != NULL)
+	if ((p = strchr(s, '=')) != NULL) {
 		*p++='\0';
+		len = strlen(p);
+		q = xmalloc(len+4);
+		sprintf(q, "-1#%s", p);
+		p = q;
+	}
 	sym = install(NS_CPP, lookup(NS_CPP, s));
 	sym->u.s = p;
 	return sym;