diff options
| author | 2025-11-16 12:11:18 +0100 | |
|---|---|---|
| committer | 2025-11-16 12:11:18 +0100 | |
| commit | 111e71e1511b2abff9176bd6c714c8da796f770e (patch) | |
| tree | 352b723c9144c844037447bd865a8366378df7a5 /test/09-varargs.c | |
| parent | b0c0f2d2d885c5901de08ed08dba9fff079bf6e3 (diff) | |
basic automated testing
Diffstat (limited to 'test/09-varargs.c')
| -rw-r--r-- | test/09-varargs.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/09-varargs.c b/test/09-varargs.c new file mode 100644 index 0000000..c15b887 --- /dev/null +++ b/test/09-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)); +} |