加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

是否存在非数组不完整类型?

发布时间:2020-12-16 10:14:16 所属栏目:百科 来源:网络整理
导读:我在C11标准中找到的所有不完整类型都是不完整的数组类型. 我想知道是否存在非数组不完整类型. 解决方法 供参考,什么是不完整的,完整的? At various points within a translation unit an object type may be incomplete (lacking sufficient information t
我在C11标准中找到的所有不完整类型都是不完整的数组类型.

我想知道是否存在非数组不完整类型.

解决方法

供参考,什么是不完整的,完整的?

At various points within a translation unit an object type may be
incomplete (lacking sufficient information to determine the size of objects of that type) or complete (having sufficient information). C11 §6.2.5 1

除了可能的struct,union,数组和总是void之外,枚举暂时不完整,因为它们的大小不完整,直到}

… The enumerated type is incomplete until immediately after the } that terminates the list of enumerator declarations,and complete thereafter. C11 §6.7.2.2 4

int main() {
  enum ee1 { a1 = 0,b1 = sizeof(int),c1 };
  printf("%zun",sizeof(enum ee1));  // OK

  // error: invalid application of 'sizeof' to incomplete type 'enum ee2'
  //                                        v--------------v 
  enum ee2 { a2 = 0,b2 = sizeof(int),c2 = sizeof(enum ee2) }; // Bad
  printf("%zun",sizeof(enum ee2)); // OK
}

进一步

All declarations of structure,or enumerated types that have the same scope and use the same tag declare the same type. Irrespective of whether there is a tag or what other declarations of the type are in the same translation unit,the type is incomplete until immediately after the closing brace of the list defining the content,and complete thereafter. §6.7.2.3 4

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读