boot2

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

347-aggregate-indirect-arg.c (775B)


      1 /* Aggregates wider than two target words are passed through a pointer to a
      2  * caller-owned copy.  The callee may mutate its by-value parameter without
      3  * changing the source object. */
      4 struct BigArg {
      5     long a;
      6     long b;
      7     long c;
      8 };
      9 
     10 static long consume(struct BigArg value, long bias)
     11 {
     12     long sum = value.a + value.b + value.c + bias;
     13     value.a = 99;
     14     return sum;
     15 }
     16 
     17 static long consume_after(long bias, struct BigArg value)
     18 {
     19     value.b = 20;
     20     return bias + value.a + value.b + value.c;
     21 }
     22 
     23 int main(void)
     24 {
     25     struct BigArg value = { 1, 2, 3 };
     26     long got = consume(value, 4);
     27     if (got != 10) return 1;
     28     if (value.a != 1) return 2;
     29     got = consume_after(4, value);
     30     if (got != 28) return 3;
     31     if (value.b != 2) return 4;
     32     return 0;
     33 }