76-vararg-recv.c (657B)
1 /* §G.2 — variadic receive: __builtin_va_start / arg / end. 2 * 3 * Mirrors what <stdarg.h> would ship: va_list = char*; va_start / 4 * va_arg / va_end are macro-aliases for the __builtin_* names. Here 5 * the test uses the builtins directly, since the cc-parse pipeline 6 * doesn't fold #include. */ 7 8 typedef char *va_list; 9 10 int sum(int n, ...) { 11 va_list ap; 12 int total; 13 int i; 14 __builtin_va_start(ap, n); 15 total = 0; 16 i = 0; 17 while (i < n) { 18 total = total + __builtin_va_arg(ap, int); 19 i = i + 1; 20 } 21 __builtin_va_end(ap); 22 return total; 23 } 24 25 int main(void) { 26 return sum(3, 5, 7, 9); /* 5 + 7 + 9 = 21 */ 27 }