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

前端之家收集整理的这篇文章主要介绍了C 11标准参考类型说明符用途中允许的类型定义?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在C 11中,类型说明符包括类说明符和枚举说明符. (又名类定义和枚举定义)

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

例如:@H_403_3@

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表达式中不能定义类型的规则在哪里?@H_403_3@

解决方法

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

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

这在7.1.6 / 3中明确地被声明:@H_403_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.@H_403_3@

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

原文链接:https://www.f2er.com/c/114555.html

猜你在找的C&C++相关文章