Why does a C/C++ compiler need know the size of an array at compile time?

后端 未结 6 987
旧巷少年郎
旧巷少年郎 2020-11-29 19:19

I know C standards preceding C99 (as well as C++) says that the size of an array on stack must be known at compile time. But why is that? The array on stack is allocated at

6条回答
  •  情歌与酒
    2020-11-29 19:29

    The compiler has to generate the code to create the space for the frame on the stack to hold the array and other local local variables. For this it needs the size of the array.

提交回复
热议问题