简体   繁体   English

标准中哪里说下面的 typedef 是有效的?

[英]Where in the standard does it say that the typedef below is valid?

Both g++ and clang++ compile this snippet: g++clang++编译这个片段:

typedef int int3[];
int3 i { 0, 1, 2 };

But where in the standard does it say that the array typedef declaration above is valid?但是标准中哪里说上面的数组typedef声明是有效的?

How do you infer that int3[] is a "synonym" for int[] ?您如何推断int3[]int[]的“同义词”?

But where in the standard does it say that the typedef declaration above is valid?但是标准中哪里说上面的 typedef 声明是有效的?

It's valid.这是有效的。 As per the standard:按照标准:

9.2.4 The typedef specifier [dcl.typedef] 9.2.4 typedef 说明符 [dcl.typedef]

1 - Declarations containing the decl-specifier typedef declare identifiers that can be used later for naming fundamental (6.8.2) or compound (6.8.3) types. 1 - 包含 decl 说明符 typedef 的声明声明了以后可用于命名基本 (6.8.2) 或复合 (6.8.3) 类型的标识符。 [...] [...]

Where:在哪里:

6.8.3 Compound types [basic.compound] 6.8.3 复合类型 [basic.compound]

1 - Compound types can be constructed in the following ways: 1 - 可以通过以下方式构造复合类型:

— (1.1) arrays of objects of a given type, 9.3.4.5; — (1.1) arrays 给定类型的对象,9.3.4.5;

[...] [...]


How do you infer that int3[] is a "synonym" for int[] ?您如何推断int3[]int[]的“同义词”?

The declaration is well defined, including for arrays with unknown bounds:声明定义明确,包括具有未知边界的 arrays:

9.3.4.5 Arrays [dcl.array] 9.3.4.5 Arrays [dcl.array]

[...] [...]

5 - Any type of the form “cv-qualifier-seq array of NU” is adjusted to “array of N cv-qualifier-seq U”, and similarly for “array of unknown bound of U”. 5 - 任何形式的“cv-qualifier-seq array of NU”都被调整为“array of N cv-qualifier-seq U”,同样适用于“array of unknown bound of U”。

[...] [...]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 标准中的哪个地方说下面调用B :: foo()是合法的? - Where in the Standard does it say that calling B::foo() below is legal? 在C ++标准中它说的是什么:: delete可以改变左值? - Where in the C++ Standard does it say ::delete can change lvalues? 标准中的哪个地方表示声明`auto f()() - &gt; int;`是不允许的? - Where in the Standard does it say that the declaration `auto f()() ->int;` is not allowed? C ++标准在哪里说,C在哪里说相同:编译单元(.cpp文件)中的变量按声明顺序初始化 - Where does the C++ standard say, and does C say the same: variables in a compilation unit (.cpp file) are initialised in order of declaration 标准中的哪个地方说&#39;new`返回的每个分配都与`std :: max_align_t`对齐? - Where in the Standard does it say that every allocation returned by `new` is aligned to `std::max_align_t`? 在C ++标准中,它表示sizeof(wchar_t)<= sizeof(long)和sizeof(bool)<= sizeof(long)? - Where in the C++ Standard does it say that sizeof(wchar_t) <= sizeof(long) and sizeof(bool) <= sizeof(long)? C++ 标准究竟在哪里说取消引用未初始化的指针是未定义的行为? - Where exactly does C++ standard say dereferencing an uninitialized pointer is undefined behavior? 在C ++ 14 Standard中,它表示非constexpr函数不能用于constexpr函数的定义吗? - Where in C++14 Standard does it say that a non-constexpr function cannot be used in a definition of a constexpr function? 标准中的哪个地方说编译器应该忽略U :: j的默认成员初始值设定项? - Where in the Standard does it say that the default member initializer for U::j should be ignored by the compiler? 在C ++ 11标准中,它表示char * p =“abc”;是不是形成了? - Where in the C++11 Standard does it say that char* p = “abc”; is ill-formed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM