Wednesday, April 8, 2009

Clark Cox on VLAs

Clark S. Cox, III, a Cocoa developer and fairly frequent contributor to the cocoa-dev mailing list, points out a major flaw in C99's variable length arrays (VLAs) on his blog today. While it is nice to be able to allocate arrays on the stack, I'm with Clark on this one: use malloc() (or one of its brethren like calloc()) followed by free() for any potentially large arrays so you don't have to worry about undefined behavior when your array is too big to fit on the stack.

Now, excuse me, I've got to check some code where I think I used VLAs for potentially large arrays.

No comments: