diff options
Diffstat (limited to 'tests/i/extern-c-variadic/lib.c')
| -rw-r--r-- | tests/i/extern-c-variadic/lib.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/i/extern-c-variadic/lib.c b/tests/i/extern-c-variadic/lib.c new file mode 100644 index 0000000..8f723a5 --- /dev/null +++ b/tests/i/extern-c-variadic/lib.c @@ -0,0 +1,20 @@ +#include <stdarg.h> + +/* Each argument after n arrives promoted, so va_arg reads int or double. */ +int sum_ints(int n, ...) { + va_list ap; + int total = 0; + va_start(ap, n); + for (int i = 0; i < n; ++i) total += va_arg(ap, int); + va_end(ap); + return total; +} + +double sum_doubles(int n, ...) { + va_list ap; + double total = 0; + va_start(ap, n); + for (int i = 0; i < n; ++i) total += va_arg(ap, double); + va_end(ap); + return total; +} |
