boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

67-vararg-call.c (608B)


      1 /* §G.1 — variadic call: caller default-promotes args.
      2  *
      3  * Declares sum3 as (int n, ...). Defines a same-ABI sum3 that takes
      4  * three ints. Calls sum3(1, c, s) where c is signed char = -3 and s
      5  * is short = 100. Per default-promote rules, c and s are promoted to
      6  * int before the call, so the callee's a1/a2 hold -3 and 100 with
      7  * full 32-bit sign-extension.
      8  *
      9  * Result: 1 + (-3) + 100 = 98.
     10  */
     11 
     12 int sum3(int n, ...);
     13 
     14 int main(void) {
     15     signed char c; short s;
     16     c = -3; s = 100;
     17     return sum3(1, c, s);  /* 1 + (-3) + 100 = 98 */
     18 }
     19 
     20 int sum3(int n, int a, int b) {
     21     return n + a + b;
     22 }