在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不定义类或枚举,除非…
原文地址:https://www.jb51.cc/c/114555.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。