【发布时间】:2011-05-19 12:00:15
【问题描述】:
我知道 C99(以及 C++)之前的 C 标准规定堆栈上数组的大小必须在编译时知道。但这是为什么呢?堆栈上的数组是在运行时分配的。那么为什么大小在编译时很重要?希望有人向我解释编译器在编译时将如何处理大小。谢谢。
这样一个数组的例子是:
void func()
{
/*Here "array" is a local variable on stack, its space is allocated
*at run-time. Why does the compiler need know its size at compile-time?
*/
int array[10];
}
【问题讨论】: