diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-22 13:23:04 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-22 13:23:04 +0000 |
| commit | eaad9c34403f05372c1544d7ef522c847dfea0ba (patch) | |
| tree | 4cd2dbaadecbfafe7855ad8ae03c046a8947697d /tests/i/extern-c-variadic/lib.c | |
| parent | 628270661843c4d61a2b5bc656daeb3099850e64 (diff) | |
test(extern): check variadic promotions with va_arg
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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; +} |
