### Question 6.15

How can I declare local arrays of a size matching a passed-in array?

You can't, in C. Array dimensions must be compile-time constants. (`gcc` provides parameterized arrays as an extension.) You'll have to use `malloc`, and remember to call `free` before the function returns. See also questions 6.14, 6.16, 6.19, 7.22, and maybe 7.32.

References: ANSI Sec. 3.4, Sec. 3.5.4.2
ISO Sec. 6.4, Sec. 6.5.4.2

Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995 // mail feedback