Malcolm said:
There are however good reasons for providing small stacks. Firstly stack
usage increases only as the logarithm of the size of a structured program.
Secondly, most processors implement cache schemes and if the stack is small
enough to ensure that it is always held in the cache, there is likely to be
a performance improvement. Thirdly, it is unusual to know the size of a big
data item at compile time, and pre 99 C doesn't allow variable size stack
arrays.
Troll? Or merely tripe? None of the three points
seems to make any sense at all:
- "Stack grows as the logarithm of program size"
First, there's no hint of how "program size" is
to be measured. Lines of code? Value of some
fundamental parameter (e.g., number of items to
sort)? Either way, it's dead easy to point to
plenty of existing counterexamples.
Of course, the counterexamples might be dismissed
on the grounds of not being "structured," but no
definition of "structured" is evident. Perhaps we
should say that "a structured program is one whose
stack size grows as the logarithm of its own size,"
but then the whole argument degenerates to tautology.
- "Stack is small so as to fit in a cache"
Balderdash. Cache friendliness (which involves far
more than mere size, by the way) is just as important
for code and for non-stack data as for stack-resident
data, so this argument leads to no special criterion
for stack size that wouldn't apply to everything else.
- "Stack is small because VLAs are new in C99"
Nonsense. VLAs have been with us for years and years,
albeit not in Standard C. But where did anybody get
the notion that machines and their operating systems
are designed solely with C in mind? Fortran, anyone?
Pascal? C with extensions like alloca()? This
argument isn't right; it's not even wrong.
Size limitations on stack-resident data (if either the stack
or limitations on it exist) are entirely implementation-dependent,
and are imposed (or not) for reasons the implementor considers
important. What those reasons might be are of no concern to the
C programmer, and the pseudo-reasons advanced above are simply
useless. Or worse.