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

C 11标准参考类型说明符用途中允许的类型定义?

发布时间:2020-12-16 05:30:52 所属栏目:百科 来源:网络整理
导读:在C 11中,类型说明符包括类说明符和枚举说明符. (又名类定义和枚举定义) 根据语法/语法 – 类型说明符可以出现在语言的多个位置,但不能在所有这些位置都允许类说明符和枚举说明符. 例如: struct C{} c;// ok: types may be defined in the specifiers of a
在C 11中,类型说明符包括类说明符和枚举说明符. (又名类定义和枚举定义)

根据语法/语法 – 类型说明符可以出现在语言的多个位置,但不能在所有这些位置都允许类说明符和枚举说明符.

例如:

struct C{} c;
// ok: types may be defined in the specifiers of a simple declaration

void f(struct S{});
// error: types may not be defined in parameter types

constexpr auto i = sizeof(enum E{});
// error: types may not be defined in ‘sizeof’ expressions

标准中的哪一个将类型说明符的这些用途分成那些可能而且可能不被定义的类型例如,在sizeof表达式中不能定义类型的规则在哪里?

解决方法

C标准中无法找到的原因是因为C标准的增量实际上是禁止的.

在C.1.4中,我们具有以下内容:更改:必须在声明中声明类型,而不是在表达式中.在C中,sizeof表达式或转换表达式可能会创建一个新类型.这显示了有关的禁令.

这在7.1.6 / 3中明确地被声明:

At least one type-specifier that is not a cv-qualifier is required in
a declaration unless it declares a constructor,destructor or
conversion function.92 A type-specifier-seq shall not define a class
or enumeration unless it appears in the type-id of an
alias-declaration (7.1.3) that is not the declaration of a
template-declaration.

特别感兴趣的部分是A类型说明符seq不定义类或枚举,除非…

(编辑:李大同)

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

    推荐文章
      热点阅读