我想全面理解C11语言的类型层次结构并以图形方式呈现出来(树状图将是完美的)。标准未提供该问题的任何图表 - 仅有30个描述各个类型及其关系的要点。我想自己画出来。
我的尝试从获取ISO/IEC 9899:201x委员会草案N1570开始,并从文档的6.2.5节中提取所有必要的语句。然后,我开始以树的形式重新排列这些知识。让我分两步介绍我的工作。
第一步:第1-15点
提取的知识(6.2.5节内的点 + 指定产生式):
- 1 类型 = 对象类型 + 函数类型; - 4 标准有符号整数类型 = signed char, short int, int, long int, long long int; - 4 有符号整数类型 = 标准有符号整数类型 + 扩展有符号整数类型; - 6 标准无符号整数类型 = _Bool, unsigned char, unsigned short int, unsigned int, unsigned long int, unsigned long long int; - 6 无符号整数类型 = 标准无符号整数类型 + 扩展无符号整数类型; - 7 标准整数类型 = 标准有符号整数类型 + 标准无符号整数类型; - 7 扩展整数类型 = 扩展有符号整数类型 + 扩展无符号整数类型; - 10 实浮点类型 = float, double, long double; - 11 复合类型 = float _Complex, double _Complex, long double _Complex; - 12 浮点类型 = 实浮点类型 + 复合类型; - 14 基本类型 = char + 有符号整数类型 + 无符号整数类型 + 浮点类型; - 15 字符类型 = char, signed char, unsigned char。
结果如下:
我的尝试从获取ISO/IEC 9899:201x委员会草案N1570开始,并从文档的6.2.5节中提取所有必要的语句。然后,我开始以树的形式重新排列这些知识。让我分两步介绍我的工作。
第一步:第1-15点
提取的知识(6.2.5节内的点 + 指定产生式):
- 1 类型 = 对象类型 + 函数类型; - 4 标准有符号整数类型 = signed char, short int, int, long int, long long int; - 4 有符号整数类型 = 标准有符号整数类型 + 扩展有符号整数类型; - 6 标准无符号整数类型 = _Bool, unsigned char, unsigned short int, unsigned int, unsigned long int, unsigned long long int; - 6 无符号整数类型 = 标准无符号整数类型 + 扩展无符号整数类型; - 7 标准整数类型 = 标准有符号整数类型 + 标准无符号整数类型; - 7 扩展整数类型 = 扩展有符号整数类型 + 扩展无符号整数类型; - 10 实浮点类型 = float, double, long double; - 11 复合类型 = float _Complex, double _Complex, long double _Complex; - 12 浮点类型 = 实浮点类型 + 复合类型; - 14 基本类型 = char + 有符号整数类型 + 无符号整数类型 + 浮点类型; - 15 字符类型 = char, signed char, unsigned char。
结果如下:
types
object types
function types
basic types
char
sίgned integer types
standard sίgned integer types
signed char, short int, int, long int, long long int
extended sίgned integer types
unsίgned integer types
standard unsίgned integer types
_Bool, unsigned char, unsigned short int, unsigned int,
unsigned long int, unsigned long long int
extended unsίgned integer types
floating types
real floating types
float, double, long double
complex types
float _Complex, double _Complex, long double _Complex
standard integer types
standard sίgned integer types
standard unsίgned integer types
extended integer types
extended sίgned integer types
extended unsίgned integer types
character types
char, signed char, unsigned char
第二步:第16-24点
剩下的语句:
- 16 枚举类型;
- 17 整型 =
char
+ 有符号整型 + 无符号整型 + 枚举类型; - 17 实型 = 整型 + 实浮点型;
- 18 算术类型 = 整型 + 浮点型;
- 20 派生类型 = 数组类型、结构体类型、联合类型、函数类型、指针类型、原子类型;
- 21 标量类型 = 算术类型 + 指针类型;
- 21 聚合类型 = 数组类型 + 结构体类型;
- 24 派生声明类型 = 数组类型 + 函数类型 + 指针类型。
最终的C11类型系统结构:
types
object types
function types
basic types
char
sίgned integer types
standard sίgned integer types
signed char, short int, int, long int, long long int
extended sίgned integer types
unsίgned integer types
standard unsίgned integer types
_Bool, unsigned char, unsigned short int, unsigned int,
unsigned long int, unsigned long long int
extended unsίgned integer types
floating types
real floating types
float, double, long double
complex types
float _Complex, double _Complex, long double _Complex
standard integer types
standard sίgned integer types
standard unsίgned integer types
extended integer types
extended sίgned integer types
extended unsίgned integer types
character types
char, signed char, unsigned char
real types
integer types
char
sίgned integer types
standard sίgned integer types
signed char, short int, int, long int, long long int
extended sίgned integer types
unsίgned integer types
standard unsίgned integer types
_Bool, unsigned char, unsigned short int, unsigned int,
unsigned long int, unsigned long long int
extended unsίgned integer types
enumeration types
real floating types
float, double, long double
scalar types
arithmetic types
integer types
char
sίgned integer types
standard sίgned integer types
signed char, short int, int, long int, long long int
extended sίgned integer types
unsίgned integer types
standard unsίgned integer types
_Bool, unsigned char, unsigned short int, unsigned int,
unsigned long int, unsigned long long int
extended unsίgned integer types
enumeration types
floating types
real floating types
float, double, long double
complex types
float _Complex, double _Complex, long double _Complex
pointer types
derived types
array types
structure types
unίon types
function types
pointer types
atomic types
aggregate types
array type
structure type
derived declarator types
array type
structure type
pointer type
现在我需要简化结构(理想情况下是一个单独的树形结构),或找到更巧妙的方式来表示关系。我想要为C11类型系统制作一张漂亮的速查表。有什么建议吗?
wchar_t
吗? C11 3.7.3 - chux - Reinstate Monica_Atomic
的评论,这并不完全正确。它可以出现为两个不同的含义,而且非常接近:作为一个限定符,因此您应该将其与其他限定符一起列出;作为类型说明符。后者是带有()
的那个,只有使用它才能将相应的原子类型视为派生类型,尽管这听起来很奇怪。 - Jens Gustedt