From 4ee0f45c1b1713521c2030de1f51290e50f546ff Mon Sep 17 00:00:00 2001 From: lemon Date: Thu, 18 Dec 2025 20:43:45 +0100 Subject: cpp: GNU extension for named variadic arguments --- c/lex.c | 11 +++++++---- test/07-pp.c | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/c/lex.c b/c/lex.c index b9b2635..e9333fc 100644 --- a/c/lex.c +++ b/c/lex.c @@ -781,13 +781,16 @@ ppdefine(struct lexer *lx) if (mac.variadic) { error(&tk.span, "expected `)' after `...'"); if (tk.t == TKEOF || tk.t == '\n') return; - else break; + break; } if (params.n > 0) { - if (tk.t != ',') { + if (tk.t == TKDOTS) { /* GNU extension 'args...' */ + mac.variadic = 1; + continue; + } if (tk.t != ',') { error(&tk.span, "expected `,' or `)'"); if (tk.t == TKEOF || tk.t == '\n') return; - else break; + break; } lex0(lx, &tk); } @@ -799,7 +802,7 @@ ppdefine(struct lexer *lx) } else { error(&tk.span, "expected parameter name or `)'"); if (tk.t == TKEOF || tk.t == '\n') return; - else break; + break; } } if (!params.n) vfree(¶ms); diff --git a/test/07-pp.c b/test/07-pp.c index 6a50571..47b9dbb 100644 --- a/test/07-pp.c +++ b/test/07-pp.c @@ -6,6 +6,7 @@ Foo,5 9 1506 join: "x ## y" wide L"abc123 猫,€á💫", U+1f98b Output ends here +ok ... */ #include "07-pp.h" @@ -31,6 +32,8 @@ u\ t\ s +#define gnu_ext(a, c...) a(c) + #ifdef CMD_WORKING int main(V) @@ -60,6 +63,7 @@ S\ * escapes the 0, ending the string early. */ ); + gnu_ext(printf, "ok %s\n", "..."); CAT(ret,urn) 0; } -- cgit v1.2.3