aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/10-varargs.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-11-19 17:24:17 +0100
committerlemon <lsof@mailbox.org>2025-11-19 17:24:17 +0100
commit9d043755a73c170b56d364a0a671f18700a2aa19 (patch)
treec2b596ed12df0d07ad1835488f6f91801fe0f979 /test/10-varargs.c
parent34ff9d31d2ead5bdc2a22518c4496b8070fd679b (diff)
rename test/varargs
Diffstat (limited to 'test/10-varargs.c')
-rw-r--r--test/10-varargs.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/10-varargs.c b/test/10-varargs.c
new file mode 100644
index 0000000..c15b887
--- /dev/null
+++ b/test/10-varargs.c
@@ -0,0 +1,23 @@
+/* EXPECT:
+1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36
+*/
+
+
+#include <stdarg.h>
+#include <stdio.h>
+
+int sum(int x, ...) {
+ va_list ap;
+ va_start(ap, x);
+ printf("%d", x);
+ for (int y; (y = va_arg(ap, int));) {
+ printf(" + %d",y);
+ x += y;
+ }
+ va_end(ap);
+ return x;
+}
+
+int main() {
+ printf(" = %d\n", sum(1,2,3,4,5,6,7,8,0,0));
+}