diff options
Diffstat (limited to 'tests/i/extern-c-struct/lib.c')
| -rw-r--r-- | tests/i/extern-c-struct/lib.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/i/extern-c-struct/lib.c b/tests/i/extern-c-struct/lib.c index 39380ec..65080f1 100644 --- a/tests/i/extern-c-struct/lib.c +++ b/tests/i/extern-c-struct/lib.c @@ -1,3 +1,5 @@ +#include <stdarg.h> + struct Sample { char tag; double value; @@ -9,3 +11,13 @@ static struct Sample shared = {'G', 0.5, 7}; void scale_sample(struct Sample *s, int k) { s->value *= k; } struct Sample *shared_sample(void) { return &shared; } int shared_count(void) { return shared.count; } + +/* Each argument after n is a struct Sample *, read back with va_arg. */ +int sum_counts(int n, ...) { + va_list ap; + int total = 0; + va_start(ap, n); + for (int i = 0; i < n; ++i) total += va_arg(ap, struct Sample *)->count; + va_end(ap); + return total; +} |
