aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2022-03-22 00:40:28 -0700
committerMichael Forney <mforney@mforney.org>2022-03-22 01:58:31 -0700
commitf2bfceac44e478f7c8828ef3624ab0c8a5b6c97b (patch)
tree79e66dd502924c32c6ae51665dc2b338e32eb94a
parent2ef69c243bf05282071b9fd66e9ab2ffb8c25783 (diff)
Allow unnamed parameters in function definitions
-rw-r--r--doc/c23.md6
-rw-r--r--qbe.c4
-rw-r--r--test/func-unnamed-param.c1
-rw-r--r--test/func-unnamed-param.qbe6
4 files changed, 15 insertions, 2 deletions
diff --git a/doc/c23.md b/doc/c23.md
index d91a40f..bc1acb0 100644
--- a/doc/c23.md
+++ b/doc/c23.md
@@ -25,6 +25,11 @@ In previous revisions of C, labels like `foo:`, `case 123:`, or
and they can now appear intermixed with declarations in compound
statements.
+## [N2510]: Allow unnamed parameters in a function definition
+
+C23 allows you to omit the name of a parameter in the prototype of
+a function definition that does not use that parameter.
+
## [N2549]: Binary integer constants
C23 allows binary integer constants in addition to octal, decimal,
@@ -33,4 +38,5 @@ and hexadecimal, using syntax like `0b01101011`.
[N2265]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2265.pdf
[N2418]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2418.pdf
[N2508]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2508.pdf
+[N2510]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2510.pdf
[N2549]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2549.pdf
diff --git a/qbe.c b/qbe.c
index a675c4e..061e6ac 100644
--- a/qbe.c
+++ b/qbe.c
@@ -487,12 +487,12 @@ mkfunc(struct decl *decl, char *name, struct type *t, struct scope *s)
/* allocate space for parameters */
for (p = t->u.func.params; p; p = p->next) {
- if (!p->name)
- error(&tok.loc, "parameter name omitted in definition of function '%s'", name);
pt = t->u.func.isprototype ? p->type : typepromote(p->type, -1);
emittype(pt);
p->value = xmalloc(sizeof(*p->value));
functemp(f, p->value);
+ if(!p->name)
+ continue;
d = mkdecl(DECLOBJECT, p->type, p->qual, LINKNONE);
if (p->type->value) {
d->value = p->value;
diff --git a/test/func-unnamed-param.c b/test/func-unnamed-param.c
new file mode 100644
index 0000000..30680b8
--- /dev/null
+++ b/test/func-unnamed-param.c
@@ -0,0 +1 @@
+void f(int) {}
diff --git a/test/func-unnamed-param.qbe b/test/func-unnamed-param.qbe
new file mode 100644
index 0000000..d4087cd
--- /dev/null
+++ b/test/func-unnamed-param.qbe
@@ -0,0 +1,6 @@
+export
+function $f(w %.1) {
+@start.1
+@body.2
+ ret
+}