summaryrefslogtreecommitdiff
path: root/tests/va_start.c
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthew@masot.net>2023-07-25 14:58:33 -0700
committerMatthew Sotoudeh <matthew@masot.net>2023-07-25 14:58:33 -0700
commit1d943da0cf9154e7ce78ce867cdbb91531c5d78e (patch)
tree40c5c6c3ba7fafa6567aa5b5aa216caecf3935fc /tests/va_start.c
initial dietc commit
Diffstat (limited to 'tests/va_start.c')
-rw-r--r--tests/va_start.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/va_start.c b/tests/va_start.c
new file mode 100644
index 0000000..8644950
--- /dev/null
+++ b/tests/va_start.c
@@ -0,0 +1,21 @@
+// https://en.cppreference.com/w/cpp/utility/variadic/va_start
+
+#include <stdio.h>
+#include <stdarg.h>
+
+int add_nums(int count, ...)
+{
+ int result = 0;
+ va_list args;
+ va_start(args, count);
+ for (int i = 0; i < count; ++i) {
+ result += va_arg(args, int);
+ }
+ va_end(args);
+ return result;
+}
+
+int main()
+{
+ printf("%d\n", add_nums(4, 25, 25, 50, 50));
+}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback