shithub: scc

Download patch

ref: 1e29199cbbb7d19343dae9c89493b5a9cb40caf9
parent: fbf8bb861d0aa96307dec739ca80167b689d5ab2
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Jan 13 10:09:17 EST 2017

[cc1] Accept variadic macro definitions

This is the first patch oriented to the implementation of variadic macros,
and it allows to define them and to use them, but it does not allow to
call them with parameters in the variable part.

--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -295,6 +295,10 @@
 			cpperror("too many parameters in macro");
 			return NR_MACROARG;
 		}
+		if (accept(ELLIPSIS)) {
+			args[n++] = NULL;
+			break;
+		}
 		if (yytoken != IDEN) {
 			cpperror("macro arguments must be identifiers");
 			return NR_MACROARG;
@@ -391,6 +395,8 @@
 	namespace = NS_IDEN;       /* Avoid polution in NS_CPP */
 	if ((n = getpars(args)) == NR_MACROARG)
 		goto delete;
+	if (n > 0 && !args[n-1])  /* it is a variadic function */
+		--n;
 	sprintf(buff, "%02d#", n);
 	if (!getdefs(args, n, buff+3, LINESIZ-3))
 		goto delete;