43-array-param-decay.c (627B)
1 // tests/cc-parse/43-array-param-decay.c — T[] in fn-param position 2 // decays to T* (§L.2 of docs/CC-PUNCHLIST.md). The callee declares 3 // `int a[]`; the parser must rewrite it to `int *` before slot 4 // allocation so `a[i]` indexes through a real pointer (not via an 5 // array slot, which would be 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 }