简体   繁体   English

int A [] = {}在C中意味着什么?

[英]What does int A[]={} mean in C?

I came across this piece of code. 我遇到了这段代码。 It doesn't give an error, but what exactly does it mean? 它没有给出错误,但是究竟是什么意思呢?

int A[]={};

EDIT: I had to edit this post because some of you asked for context, compiler and so on.. 编辑:我不得不编辑这篇文章,因为你们中的一些人要求上下文,编译器等。

I do not know much about compilers but i managed to found the version i'm using "gcc (tdm-1) 4.9.2". 我对编译器了解不多,但是我设法找到了我正在使用的版本“ gcc(tdm-1)4.9.2”。

I have tried the code myself and it did run correctly, i was also able to read and write on the array. 我自己尝试了该代码,它确实运行正确,我也能够在该阵列上进行读写。 My question is : What exactly happens when i declare such an array ? 我的问题是:当我声明这样的数组时,到底发生了什么?

int A[]={};

is illegal in C. Empty initializers are not valid. 在C中是非法的。空的初始化程序无效。 See C11 draft, 6.7.9 Initialization . 参见C11草案6.7.9初始化

It means nothing, it is not valid C. 没什么意思,它不是有效的C。

C11 6.7.9 states that the two following forms are valid: C11 6.7.9声明以下两种形式有效:

{ initializer-list } 
{ initializer-list , }

where initializer-list is defined as one of the following: 其中initializer-list定义为以下之一:

designationopt initializer
initializer-list , designationopt initializer

This could either be an assignment expression or a C99 designated initializer. 这可以是赋值表达式,也可以是C99指定的初始化程序。 An empty initializer list is not valid syntax. 空的初始化程序列表是无效的语法。

它定义了一个int类型的空数组。

You should show some more context, and mention which compiler was being used. 您应该显示更多上下文,并提及所使用的编译器。

I don't think that code compiles with a standards-compliant compiler, the empty initializer list makes it invalid. 我不认为代码可以使用符合标准的编译器进行编译,而空的初始化列表会使其无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM