kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

variadic_02_many_ints.c (412B)


      1 /* More than 8 variadic ints — exhausts the AAPCS64 GP save area
      2  * (x0..x7) and forces va_arg to fall through to the stack overflow
      3  * path. */
      4 int sum(int n, ...) {
      5   __builtin_va_list ap;
      6   __builtin_va_start(ap, n);
      7   int s = 0;
      8   for (int i = 0; i < n; i++) s += __builtin_va_arg(ap, int);
      9   __builtin_va_end(ap);
     10   return s;
     11 }
     12 
     13 int test_main(void) { return sum(12, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 0); }