由初始化器列表初始化的数组存储在哪里? [英] Where is an array initialized by an initializer list stored?
问题描述
给出这段代码:
(void)someFunction(void) {
int array[] = {1,2,3,4,5,6,7,8,9,10};
}
数组的值存储在哪里?
- 堆栈?
- 堆?
- 与这些字符串文字一起使用. (它叫做高频堆吗?)
- 还有其他地方吗?
我问是因为不确定这个问题:
I'm asking because I'm unsure regarding this question:
推荐答案
数组本身将位于堆栈中.该函数的入口处将有一些代码,用于将存储在全局/静态存储区中某些未命名数组中的值复制到堆栈上的本地数组中.带有初始值的未命名全局/静态数组可能与字符串文字位于相同的常规存储区中.
The array itself will be on the stack. There will be a bit of code on entry to the function that copies the values which are stored in some unnamed array in a global/static memory area into the local array on the stack. It's likely that the unnamed global/static array with the initial values is in the same general memory area as string literals.
但是请注意,该标准并不需要所有这些内容-但这几乎是任何编译器将其实现的方式.足够聪明的编译器可能会注意到这些值只是递增的整数值,并可能生成一个循环来初始化本地数组,
Note however, that none of this is required by the standard - but it's pretty much how any compiler will implement it. A smart enough compiler might notice that the values are simply incremented integer values and might gen up a loop to init the local array,
(此答案假定为C/C ++-我不知道Objective-C是否会更改其中的任何内容.)
(this answer assumes C/C++ - I don't know if Objective-C would change any of this).
这篇关于由初始化器列表初始化的数组存储在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!