shithub: scc

Download patch

ref: 539338d3e3f1ac406cd5bf8863d217bcb648e7c2
parent: e7546f194ee39c7e10e95479d594fd450ea8dff2
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Nov 17 14:29:01 EST 2021

cc1: Substitute // comments by \n

The code was substituing all the comments by a space, but it only
works with /* */ comments. // comments should be substitued by
newlines, otherwise they cannot be used in preprocessor directives
that need to be in only one line.

--- a/src/cmd/cc/cc1/lex.c
+++ b/src/cmd/cc/cc1/lex.c
@@ -219,9 +219,15 @@
 		peekc = readchar();
 		if (peekc != '*' && peekc != '/')
 			continue;
-		comment((peekc == '/') ? '\n' : '*');
+
+		if (peekc == '/') {
+			comment('\n');
+			break;
+		} else {
+			comment('*');
+			c = ' ';
+		}
 		peekc = 0;
-		c = ' ';
 	}
 
 	input->begin = input->p = input->line;