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

在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不定义类或枚举,除非…

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...