C:它是合法的下标不完全类型的数组? [英] C: Is it legal to subscript an array of incomplete type?

查看:123
本文介绍了C:它是合法的下标不完全类型的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到在标准中的相关位,但gcc和铿锵允许的话,所以我想我想知道,如果它是语言的编译器扩展或部分。如果你能提供一个链接。

I can't find the relevant bits in the standard, but gcc and clang allow it, so I guess I' wondering if it's a compiler extension or part of the language. Provide a link if you can.

这可以用的东西,如由此产生:

This can arise with things such as this:

extern char arr[];

func(arr[7]); /*No error.*/

LATE编辑:我想我会更好地得到一个清晰的认识,这是我从来没有,虽然我已经离开了,所以一开始我的赏金将奖的第一人给我一个清晰,简明的基准而( ES)在C89标准,为什么这是允许的。 C99是可以接受的,如果没有人能够找到C89的答案,但你需要在C89标准先看看。

LATE I figured I'd better get a clear understanding of this, which I never did although I had moved on, so starting a bounty which I will award to the first person to give me a clear, concise reference(es) in the C89 standard as to why this is allowed. C99 is acceptable if nobody can find the answer in C89, but you need to look in the C89 standard first.

推荐答案

下面的语句

extern char arr[];

是具有外部链接的声明,并说改编有一个类型字符的阵列,它意味着该改编可以有一个不完整的类型。

is a declaration with external linkage, and says that arr has a type of array of char, which implies that arr can have an incomplete type.

据6.7声明(n1570):

According to "6.7 Declarations" (n1570):

7,该对象的类型应
   通过在其声明月底完成,或者通过其init声明符结束时,如果它有一个
  初始化;在功能参数(包括在原型)的情况下,它是调整
  型(见6.7.6.3),该需要是完整的。

7 If an identifier for an object is declared with no linkage, the type for the object shall be complete by the end of its declarator, or by the end of its init-declarator if it has an initializer; in the case of function parameters (including in prototypes), it is the adjusted type (see 6.7.6.3) that is required to be complete.

改编[7] 等于 *(ARR + 7) ARR 需要有一种类型的指针来完成对象类型,而的改编类型将从<$ C $数组转换C>字符到指针字符,在这种情况下。

And arr[7] equals *(arr + 7), and arr need to have a type of "pointer to complete object type", and the type of arr will be converted from "array of char" to "pointer to char" in this case.

据6.3.2.1左值,数组和功能指示符(n1570):

According to "6.3.2.1 Lvalues, arrays, and function designators" (n1570):

3除非它是的sizeof 运算符的操作数,则 _Alignof 运营商,或
  一元&安培; 运营商,或者是用于初始化数组,有一个前pression一个字符串文字
  类型''类型的数组''转换为类型指向数组对象的初始元素,而不是一个左值'指向类型为'一个前pression。

3 Except when it is the operand of the sizeof operator, the_Alignof operator, or the unary & operator, or is a string literal used to initialize an array, an expression that has type ‘‘array of type’’ is converted to an expression with type ‘‘pointer to type’’ that points to the initial element of the array object and is not an lvalue.

这篇关于C:它是合法的下标不完全类型的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆