Design Element
Comment on "Intro to Memory and Arrays in C"
by Frank McCabe — Feb 21
You correctly pointed out the use of stack allocated (and dynamically sized arrays) and yes, most people have not yet heard of the latter.
However, I think that there should be a giant health warning attached to this:

the total size of a stack allocated array is limited by the maximum size of the stack. Typically, there is *no* warning given if you exceed this size.


foo(int len)
int array[len];

if you call foo with (say) 1200000, then, at least under gcc, the array will be silently given a garbage value and you use it at your own (and your customer's) risk. It is not clear what the maximum safe size of a dynamically sized array is, but gcc seems to limit it to 64K bytes.

The same applies to alloca'd memory - if its too big you get silent garbage.
Back to "Intro to Memory and Arrays in C"
Design Element

Copyright © Scott Stevenson 2004-2015