scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 26ff02d15aedb16bc16fda9a2943d75a8ae95c75
parent 1ce77f3c342d3c53596b39cd7271da9b21198813
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 13 Jan 2017 15:09:17 +0100

[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.

Diffstat:
Mcc1/cpp.c | 6++++++
1 file changed, 6 insertions(+), 0 deletions(-)

diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -295,6 +295,10 @@ getpars(Symbol *args[NR_MACROARG]) 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 @@ define(void) 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;