prev up next   top/contents search

comp.lang.c FAQ list · Question 6.15

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

A: Until recently, you couldn't; array dimensions in C traditionally had to be compile-time constants. However, C99 introduces variable-length arrays (VLA's) which solve this problem; local arrays may have sizes set by variables or other expressions, perhaps involving function parameters. (gcc has provided parameterized arrays as an extension for some time.) If you can't use C99 or gcc, 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: ISO Sec. 6.4, Sec.
C9X Sec.

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North