043-array-param-decay.c (595B)
1 // tests/cc-parse/43-array-param-decay.c — T[] in fn-param position 2 // decays to T*. The callee declares `int a[]`; the parser must 3 // rewrite it to `int *` before slot allocation so `a[i]` indexes 4 // through a real pointer (not via an array slot, which would be 5 // wrong for an actual int* argument). 6 // 7 // sum(a, 4) over {1,2,3,4} = 10. 8 9 int sum(int a[], int n) { 10 int s = 0; 11 int i = 0; 12 while (i < n) { 13 s = s + a[i]; 14 i = i + 1; 15 } 16 return s; 17 } 18 19 int main() { 20 int xs[4]; 21 xs[0] = 1; 22 xs[1] = 2; 23 xs[2] = 3; 24 xs[3] = 4; 25 return sum(xs, 4); 26 }