gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 01:04:12 24 4
gpt4 key购买 nike

g++clang++ compile这个片段:

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

但是在标准中哪里说上面的数组 typedef 声明是有效的?

你如何推断​​ int3[]int[] 的“同义词”?

最佳答案

But where in the standard does it say that the typedef declaration above is valid?

这是有效的。按照标准:

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. [...]

地点:

6.8.3 复合类型[basic.compound]

1 - Compound types can be constructed in the following ways:

— (1.1) arrays of objects of a given type, 9.3.4.5;

[...]


How do you infer that int3[] is a "synonym" for int[]?

声明定义明确,包括边界未知的数组:

9.3.4.5 数组[dcl.array]

[...]

5 - Any type of the form “cv-qualifier-seq array of N U” is adjusted to “array of N cv-qualifier-seq U”, and similarly for “array of unknown bound of U”.

[...]

关于c++ - 标准中哪里说下面的 typedef 是有效的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67064731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com