是否在存储在堆栈上的函数中声明了 const 数组? [英] Are const arrays declared within a function stored on the stack?
本文介绍了是否在存储在堆栈上的函数中声明了 const 数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果这是在函数中声明的,它会在堆栈上声明吗?(它是 const 是什么让我想知道)
if this was declared within a function, would it be declared on the stack? (it being const is what makes me wonder)
void someFunction()
{
const unsigned int actions[8] =
{ e1,
e2,
etc...
};
}
推荐答案
是的,它们在堆栈中.您可以通过查看此代码片段来了解这一点:它必须打印 5 次销毁消息.
Yes, they're on the stack. You can see this by looking at this code snippet: it will have to print the destruction message 5 times.
struct A { ~A(){ printf( "A destructed\n" ); } };
int main() {
{
const A anarray [5] = {A()} ;
}
printf( "inner scope closed\n");
}
这篇关于是否在存储在堆栈上的函数中声明了 const 数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文