C语言 什么是“接近初始化”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23415158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is "near-initialization"?
提问by captaincurrie
In C, what does a "near-initialization" error mean?
在 C 中,“接近初始化”错误是什么意思?
For instance, the following will generate the error:
例如,以下将产生错误:
int a[9] = {{1,2,3},{2,3,4},{3,4,5}}
p.s Why does this example generate the error?
ps 为什么这个例子会产生错误?
回答by AntonH
To combine my and @luk32's comments (edit: and @hans-passant).
结合我和@luk32 的评论(编辑:和@hans-passant)。
Your error isn't so much an error, as it is a warning that you have a potential problem. It is near (as in, close by) the element a(there is no hyphen betyween "near" and "initialization", so the warning is near the element mentionned in the warning message; a "near-initialization" would mean that the element was almost but not quite initialised, which makes no sense).
您的错误与其说是错误,不如说是警告您有潜在问题。它靠近(如靠近)元素a(“near”和“initialization”之间没有连字符,因此警告靠近警告消息中提到的元素;“near-initialization”意味着元素几乎但没有完全初始化,这是没有意义的)。
int a[9] = {{1,2,3},{2,3,4},{3,4,5}}
Basically, you have a 1D array of size 9. But in your initialisation, you are treating it like a 2D 3x3 array. While they take up the same amount of space in memory, they are treated a little differently.
基本上,你有一个大小为 9 的一维数组。但是在你的初始化中,你把它当作一个 2D 3x3 数组。虽然它们在内存中占用相同数量的空间,但它们的处理方式略有不同。
To resolve the problem, you would have to either change the definition:
要解决此问题,您必须更改定义:
int a[3][3] = {{1,2,3},{2,3,4},{3,4,5}}
Or the initialisation:
或者初始化:
int a[9] = {1,2,3,2,3,4,3,4,5}
Informational link:
资料链接:
Provided by @luk32: http://www.microchip.com/forums/m463491.aspx
@luk32 提供:http: //www.microchip.com/forums/m463491.aspx

