097-vararg-many-named.c (858B)
1 /* Variadic with >4 named args before the ellipsis. cg.scm comment notes 2 * the save area only holds the first 4 incoming args; this probes 3 * va_arg access of variadic slots when named args already fill it. */ 4 5 #ifndef CCSCM 6 #include <stdarg.h> 7 #else 8 typedef char *va_list; 9 #define va_start(ap, n) __builtin_va_start(ap, n) 10 #define va_arg(ap, t) __builtin_va_arg(ap, t) 11 #define va_end(ap) __builtin_va_end(ap) 12 #endif 13 14 int summer(int a, int b, int c, int d, int e, ...) { 15 va_list ap; 16 int n = 3; 17 int total = a + b + c + d + e; 18 int i = 0; 19 va_start(ap, e); 20 while (i < n) { 21 total = total + va_arg(ap, int); 22 i = i + 1; 23 } 24 va_end(ap); 25 return total; 26 } 27 28 int main(int argc, char **argv) { 29 /* 1+2+3+4+5 + 6+7+8 = 36 */ 30 int r = summer(1, 2, 3, 4, 5, 6, 7, 8); 31 if (r != 36) return 1; 32 return 0; 33 }