Files
sx/examples/1229-ffi-extern-cvariadic.c
agra 9a2c78d6b9 test(ffi-linkage): Phase 5.0 prereq — xfail extern C-variadic tail loses its ...
A trailing `..args: []T` on an `extern` fn must map to the C `...` tail
like its `#foreign` twin (example 1218). Today the variadic handling in
both declareFunction (is_variadic drop) and packVariadicCallArgs
(call-site early-out) is gated on `#foreign` only, so a variadic
`extern` keeps the trailing slice param and slice-packs the extras —
garbage at the C ABI (probe: sum_ints(3,10,20,30) → 53316585, not 60).

Example 1229 pins the DESIRED correct output; the next commit extends
both gates to cover extern and greens it. Prerequisite for migrating the
fn-decl `#foreign` path onto `extern`.

645 corpus (1229 xfail), 444 unit.
2026-06-14 21:03:13 +03:00

21 lines
448 B
C

#include <stdarg.h>
long long sx_ext_sum_ints(int n, ...) {
va_list ap;
va_start(ap, n);
long long total = 0;
for (int i = 0; i < n; i++) total += va_arg(ap, int);
va_end(ap);
return total;
}
double sx_ext_avg_doubles(int n, ...) {
va_list ap;
va_start(ap, n);
double total = 0.0;
for (int i = 0; i < n; i++) total += va_arg(ap, double);
va_end(ap);
if (n == 0) return 0.0;
return total / n;
}